carlos-granados · GitHub

@carlos-granados

@carlos-granados

ndossche


if (dot == NULL) {
/* No dot found, this is a simple key lookup */
zend_string *zkey = zend_string_init(key, key_len, 0);

/* If key is null, return the whole array */
if (key == NULL || Z_TYPE_P(key) == IS_NULL) {
ZVAL_ARR(return_value, zend_array_dup(ht));
result = array_get_nested(ht, Z_STRVAL_P(key), Z_STRLEN_P(key));

if (result != NULL) {
ZVAL_COPY(return_value, result);
result = zend_hash_index_find(ht, Z_LVAL_P(key));

if (result != NULL) {
ZVAL_COPY(return_value, result);

/* Key not found, return default value */
if (default_value != NULL) {
ZVAL_COPY(return_value, default_value);
if (default_value != NULL) {
ZVAL_COPY(return_value, default_value);
} else {
RETVAL_NULL();
}

/* Invalid key type */
RETURN_FALSE;
}

/* Recurse into the nested array with the remaining key */
return array_get_nested(Z_ARRVAL_P(current), dot + 1, key_len - segment_len - 1);

ndossche

current = zend_symtable_find(ht, segment);
zend_string_release(segment);

if (current == NULL || Z_TYPE_P(current) != IS_ARRAY) {

ndossche

}

/* Handle integer keys (simple lookup) */
ZEND_ASSERT(Z_TYPE_P(key) == IS_LONG);
/* Use php_explode to split the string by '.' */
zend_string *delim = ZSTR_CHAR('.');
array_init(&segments_array);
php_explode(delim, Z_STR_P(key), &segments_array, ZEND_LONG_MAX);
result = zend_hash_index_find(ht, Z_LVAL_P(key));

if (result != NULL) {
RETURN_COPY(result);

@carlos-granados

ndossche

num_segments = zend_hash_num_elements(path);

/* Iterate through each segment in the path array */
for (idx = 0; idx < num_segments; idx++) {
}

/* Check if the segment exists and is an array for next iteration */
if (current == NULL || Z_TYPE_P(current) != IS_ARRAY) {

/* Path not found, return default value */
if (default_value != NULL) {
RETURN_COPY_DEREF(default_value);
/* {{{ Retrieves a value from a deeply nested array using an array path */
PHP_FUNCTION(array_get)
{
zval *array;
/* {{{ Helper function to get a nested value from array using an array of path segments */
static zval* array_get_nested(HashTable *ht, HashTable *path)
{
zval *segment_val;

ndossche

}

/* If this is the last segment, return the result */
if (idx == num_segments - 1) {

ndossche

}

/* Segment must be a string or int */
if (Z_TYPE_P(segment_val) == IS_STRING) {

ndossche

@carlos-granados carlos-granados changed the title Array_get and array_has functions array_path_get and array_path_exists functions

Apr 18, 2026
# Conflicts:
#	ext/standard/basic_functions_arginfo.h
#	ext/standard/basic_functions_decl.h
# Conflicts:
#	ext/standard/basic_functions_arginfo.h
#	ext/standard/basic_functions_decl.h

@carlos-granados

Read the original on github.com ↗