mirror of
https://github.com/php/php-src.git
synced 2024-09-22 10:27:25 +00:00
091d53c131
array_column() reimplements array key handling in a way that does not match standard array key behavior in PHP. Avoid this by making use of the standard API. Of course, there is a minor backwards compatibilty break here, e.g. people could be relying on objects getting cast to string instead of throwing. Closes GH-5487.
47 lines
846 B
PHP
47 lines
846 B
PHP
--TEST--
|
|
Test array_column() function: basic functionality
|
|
--FILE--
|
|
<?php
|
|
class ColumnKeyClass {
|
|
function __toString() { return 'first_name'; }
|
|
}
|
|
|
|
class IndexKeyClass {
|
|
function __toString() { return 'id'; }
|
|
}
|
|
|
|
|
|
$column_key = new ColumnKeyClass();
|
|
$index_key = new IndexKeyClass();
|
|
|
|
|
|
// Array representing a possible record set returned from a database
|
|
$records = array(
|
|
array(
|
|
'id' => 2135,
|
|
'first_name' => 'John',
|
|
'last_name' => 'XXX'
|
|
),
|
|
array(
|
|
'id' => 3245,
|
|
'first_name' => 'Sally',
|
|
'last_name' => 'Smith'
|
|
),
|
|
);
|
|
$firstNames = array_column($records, $column_key, $index_key);
|
|
print_r($firstNames);
|
|
var_dump($column_key);
|
|
var_dump($index_key);
|
|
|
|
?>
|
|
--EXPECT--
|
|
Array
|
|
(
|
|
[2135] => John
|
|
[3245] => Sally
|
|
)
|
|
object(ColumnKeyClass)#1 (0) {
|
|
}
|
|
object(IndexKeyClass)#2 (0) {
|
|
}
|