@@ -6915,6 +6915,114 @@ PHP_FUNCTION(array_key_exists)
69156915}
69166916/* }}} */
69176917
6918+ /* {{{ Helper function to get a nested value from array using dot notation */
6919+ static zval * array_get_nested (HashTable * ht , const char * key , size_t key_len )
6920+ {
6921+ const char * dot ;
6922+ zval * current ;
6923+
6924+ /* Find the first dot in the key */
6925+ dot = memchr (key , '.' , key_len );
6926+
6927+ if (dot == NULL ) {
6928+ /* No dot found, this is a simple key lookup */
6929+ zend_string * zkey = zend_string_init (key , key_len , 0 );
6930+ current = zend_symtable_find (ht , zkey );
6931+ zend_string_release (zkey );
6932+ return current ;
6933+ }
6934+
6935+ /* We have a dot, so we need to recurse */
6936+ size_t segment_len = dot - key ;
6937+ zend_string * segment = zend_string_init (key , segment_len , 0 );
6938+ current = zend_symtable_find (ht , segment );
6939+ zend_string_release (segment );
6940+
6941+ if (current == NULL || Z_TYPE_P (current ) != IS_ARRAY ) {
6942+ return NULL ;
6943+ }
6944+
6945+ /* Recurse into the nested array with the remaining key */
6946+ return array_get_nested (Z_ARRVAL_P (current ), dot + 1 , key_len - segment_len - 1 );
6947+ }
6948+ /* }}} */
6949+
6950+ /* {{{ Retrieves a value from a deeply nested array using "dot" notation */
6951+ PHP_FUNCTION (array_get )
6952+ {
6953+ HashTable * ht ;
6954+ zval * key = NULL ;
6955+ zval * default_value = NULL ;
6956+ zval * result ;
6957+
6958+ ZEND_PARSE_PARAMETERS_START (2 , 3 )
6959+ Z_PARAM_ARRAY_HT (ht )
6960+ Z_PARAM_ZVAL_OR_NULL (key )
6961+ Z_PARAM_OPTIONAL
6962+ Z_PARAM_ZVAL (default_value )
6963+ ZEND_PARSE_PARAMETERS_END ();
6964+
6965+ /* If key is null, return the whole array */
6966+ if (key == NULL || Z_TYPE_P (key ) == IS_NULL ) {
6967+ ZVAL_ARR (return_value , zend_array_dup (ht ));
6968+ return ;
6969+ }
6970+
6971+ /* Handle string keys with dot notation */
6972+ if (Z_TYPE_P (key ) == IS_STRING ) {
6973+ result = array_get_nested (ht , Z_STRVAL_P (key ), Z_STRLEN_P (key ));
6974+
6975+ if (result != NULL ) {
6976+ ZVAL_COPY (return_value , result );
6977+ return ;
6978+ }
6979+ }
6980+ /* Handle integer keys (no dot notation support) */
6981+ else if (Z_TYPE_P (key ) == IS_LONG ) {
6982+ result = zend_hash_index_find (ht , Z_LVAL_P (key ));
6983+
6984+ if (result != NULL ) {
6985+ ZVAL_COPY (return_value , result );
6986+ return ;
6987+ }
6988+ }
6989+
6990+ /* Key not found, return default value */
6991+ if (default_value != NULL ) {
6992+ ZVAL_COPY (return_value , default_value );
6993+ } else {
6994+ RETVAL_NULL ();
6995+ }
6996+ }
6997+ /* }}} */
6998+
6999+ /* {{{ Checks whether a given item exists in an array using "dot" notation */
7000+ PHP_FUNCTION (array_has )
7001+ {
7002+ HashTable * ht ;
7003+ zval * key ;
7004+ zval * result ;
7005+
7006+ ZEND_PARSE_PARAMETERS_START (2 , 2 )
7007+ Z_PARAM_ARRAY_HT (ht )
7008+ Z_PARAM_ZVAL (key )
7009+ ZEND_PARSE_PARAMETERS_END ();
7010+
7011+ /* Handle string keys with dot notation */
7012+ if (Z_TYPE_P (key ) == IS_STRING ) {
7013+ result = array_get_nested (ht , Z_STRVAL_P (key ), Z_STRLEN_P (key ));
7014+ RETURN_BOOL (result != NULL );
7015+ }
7016+ /* Handle integer keys (no dot notation support) */
7017+ else if (Z_TYPE_P (key ) == IS_LONG ) {
7018+ RETURN_BOOL (zend_hash_index_exists (ht , Z_LVAL_P (key )));
7019+ }
7020+
7021+ /* Invalid key type */
7022+ RETURN_FALSE ;
7023+ }
7024+ /* }}} */
7025+
69187026/* {{{ Split array into chunks */
69197027PHP_FUNCTION (array_chunk )
69207028{
0 commit comments