summaryrefslogtreecommitdiff
path: root/ext/standard/array.c
diff options
context:
space:
mode:
authorSara Golemon <pollita@php.net>2013-04-22 16:19:21 -0700
committerSara Golemon <pollita@php.net>2013-04-22 16:19:21 -0700
commit734e165d4e427feca9a736b62832a2ff287a22c9 (patch)
tree5e20e8b10bedebc8fe6ec9e4ec3724061a4f5b68 /ext/standard/array.c
parent1a03bd5dee97a0f8b9e74b7f8db5231abd8cc7e4 (diff)
downloadphp-git-734e165d4e427feca9a736b62832a2ff287a22c9.tar.gz
array_column() - Use entire subject array when NULL passed for second param.
This starts to look like array_values(), except that you can reindex the arrays using the third parameter.
Diffstat (limited to 'ext/standard/array.c')
-rw-r--r--ext/standard/array.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/ext/standard/array.c b/ext/standard/array.c
index 6f769da1d8..cfe9be8552 100644
--- a/ext/standard/array.c
+++ b/ext/standard/array.c
@@ -2531,7 +2531,6 @@ static inline
zend_bool array_column_param_helper(zval **param,
const char *name TSRMLS_DC) {
switch (Z_TYPE_PP(param)) {
- case IS_NULL:
case IS_DOUBLE:
convert_to_long_ex(param);
/* fallthrough */
@@ -2555,15 +2554,15 @@ zend_bool array_column_param_helper(zval **param,
value_key and optionally indexed by the index_key */
PHP_FUNCTION(array_column)
{
- zval **zcolumn, **zkey = NULL, **data;
+ zval **zcolumn = NULL, **zkey = NULL, **data;
HashTable *arr_hash;
HashPosition pointer;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "hZ|Z!", &arr_hash, &zcolumn, &zkey) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "hZ!|Z!", &arr_hash, &zcolumn, &zkey) == FAILURE) {
return;
}
- if (!array_column_param_helper(zcolumn, "column" TSRMLS_CC) ||
+ if ((zcolumn && !array_column_param_helper(zcolumn, "column" TSRMLS_CC)) ||
(zkey && !array_column_param_helper(zkey, "index" TSRMLS_CC))) {
RETURN_FALSE;
}
@@ -2581,8 +2580,12 @@ PHP_FUNCTION(array_column)
}
ht = Z_ARRVAL_PP(data);
- /* Skip if the value doesn't exist in our subarray */
- if ((Z_TYPE_PP(zcolumn) == IS_STRING) &&
+ if (!zcolumn) {
+ /* NULL column ID means use entire subarray as data */
+ zcolval = data;
+
+ /* Otherwise, skip if the value doesn't exist in our subarray */
+ } else if ((Z_TYPE_PP(zcolumn) == IS_STRING) &&
(zend_hash_find(ht, Z_STRVAL_PP(zcolumn), Z_STRLEN_PP(zcolumn) + 1, (void**)&zcolval) == FAILURE)) {
continue;
} else if ((Z_TYPE_PP(zcolumn) == IS_LONG) &&