summaryrefslogtreecommitdiff
path: root/ext/standard/array.c
diff options
context:
space:
mode:
authorEnno Woortmann <enno.woortmann@eventim.de>2018-07-17 10:29:55 +0200
committerChristoph M. Becker <cmbecker69@gmx.de>2018-07-17 11:31:00 +0200
commit50516a6e1f357f63324ec76e26623f2a7185bd4f (patch)
treeb02395bc0f298d68c85da15ca0ef27a0660f25b6 /ext/standard/array.c
parent79a27ccf3f62e25f3ce5254dbce4cd631fb4e735 (diff)
downloadphp-git-50516a6e1f357f63324ec76e26623f2a7185bd4f.tar.gz
Add implementation and tests for new methods - array_key_first(array $a) Returns the key of the first element or null - array_key_last(array $a) Returns the key of the last element or null
Diffstat (limited to 'ext/standard/array.c')
-rw-r--r--ext/standard/array.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/ext/standard/array.c b/ext/standard/array.c
index 10831a4227..82e0833e34 100644
--- a/ext/standard/array.c
+++ b/ext/standard/array.c
@@ -3963,6 +3963,39 @@ PHP_FUNCTION(array_keys)
}
/* }}} */
+/* {{{ proto mixed array_key_first(array stack)
+ Get the key of the first element of the array */
+PHP_FUNCTION(array_key_first)
+{
+ zval *stack; /* Input stack */
+
+ ZEND_PARSE_PARAMETERS_START(1, 1)
+ Z_PARAM_ARRAY_EX(stack, 0, 1)
+ ZEND_PARSE_PARAMETERS_END();
+
+ HashTable *target_hash = HASH_OF(stack);
+ HashPosition pos = 0;
+ zend_hash_get_current_key_zval_ex(target_hash, return_value, &pos);
+}
+/* }}} */
+
+/* {{{ proto mixed array_key_last(array stack)
+ Get the key of the last element of the array */
+PHP_FUNCTION(array_key_last)
+{
+ zval *stack; /* Input stack */
+ HashPosition pos;
+
+ ZEND_PARSE_PARAMETERS_START(1, 1)
+ Z_PARAM_ARRAY_EX(stack, 0, 1)
+ ZEND_PARSE_PARAMETERS_END();
+
+ HashTable *target_hash = HASH_OF(stack);
+ zend_hash_internal_pointer_end_ex(target_hash, &pos);
+ zend_hash_get_current_key_zval_ex(target_hash, return_value, &pos);
+}
+/* }}} */
+
/* {{{ proto array array_values(array input)
Return just the values from the input array */
PHP_FUNCTION(array_values)