mirror of
https://github.com/php/php-src.git
synced 2026-04-05 23:23:03 +02:00
Merge branch 'PHP-5.5'
* PHP-5.5: array_column() - Use entire subject array when NULL passed for second param.
This commit is contained in:
@@ -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) &&
|
||||
|
||||
85
ext/standard/tests/array/array_column_variant.phpt
Normal file
85
ext/standard/tests/array/array_column_variant.phpt
Normal file
@@ -0,0 +1,85 @@
|
||||
--TEST--
|
||||
Test array_column() function: variant functionality
|
||||
--FILE--
|
||||
<?php
|
||||
/* Array from Bug Request #64493 test script */
|
||||
$rows = array(
|
||||
456 => array('id' => '3', 'title' => 'Foo', 'date' => '2013-03-25'),
|
||||
457 => array('id' => '5', 'title' => 'Bar', 'date' => '2012-05-20'),
|
||||
);
|
||||
|
||||
echo "-- pass null as second parameter to get back all columns indexed by third parameter --\n";
|
||||
var_dump(array_column($rows, null, 'id'));
|
||||
|
||||
echo "-- pass null as second parameter and bogus third param to get back zero-indexed array of all columns --\n";
|
||||
var_dump(array_column($rows, null, 'foo'));
|
||||
|
||||
echo "-- pass null as second parameter and no third param to get back array_values(input) --\n";
|
||||
var_dump(array_column($rows, null));
|
||||
|
||||
echo "Done\n";
|
||||
--EXPECTF--
|
||||
-- pass null as second parameter to get back all columns indexed by third parameter --
|
||||
array(2) {
|
||||
[3]=>
|
||||
array(3) {
|
||||
["id"]=>
|
||||
string(1) "3"
|
||||
["title"]=>
|
||||
string(3) "Foo"
|
||||
["date"]=>
|
||||
string(10) "2013-03-25"
|
||||
}
|
||||
[5]=>
|
||||
array(3) {
|
||||
["id"]=>
|
||||
string(1) "5"
|
||||
["title"]=>
|
||||
string(3) "Bar"
|
||||
["date"]=>
|
||||
string(10) "2012-05-20"
|
||||
}
|
||||
}
|
||||
-- pass null as second parameter and bogus third param to get back zero-indexed array of all columns --
|
||||
array(2) {
|
||||
[0]=>
|
||||
array(3) {
|
||||
["id"]=>
|
||||
string(1) "3"
|
||||
["title"]=>
|
||||
string(3) "Foo"
|
||||
["date"]=>
|
||||
string(10) "2013-03-25"
|
||||
}
|
||||
[1]=>
|
||||
array(3) {
|
||||
["id"]=>
|
||||
string(1) "5"
|
||||
["title"]=>
|
||||
string(3) "Bar"
|
||||
["date"]=>
|
||||
string(10) "2012-05-20"
|
||||
}
|
||||
}
|
||||
-- pass null as second parameter and no third param to get back array_values(input) --
|
||||
array(2) {
|
||||
[0]=>
|
||||
array(3) {
|
||||
["id"]=>
|
||||
string(1) "3"
|
||||
["title"]=>
|
||||
string(3) "Foo"
|
||||
["date"]=>
|
||||
string(10) "2013-03-25"
|
||||
}
|
||||
[1]=>
|
||||
array(3) {
|
||||
["id"]=>
|
||||
string(1) "5"
|
||||
["title"]=>
|
||||
string(3) "Bar"
|
||||
["date"]=>
|
||||
string(10) "2012-05-20"
|
||||
}
|
||||
}
|
||||
Done
|
||||
Reference in New Issue
Block a user