note 125182 added to function.array-column
| From: | yangmeishu at live dot com | Date: | Sat, 11 Jul 2020 02:19:23 +0000 |
| Subject: | note 125182 added to function.array-column | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-214855@lists.php.net to get a copy of this message | ||
Please note that if you use array_column to reset the index, when the index value is null, there
will be different results in different PHP versions, examples
<?php
$array = [
[
'name' =>'Bob',
'house' =>'big',
],
[
'name' =>'Alice',
'house' =>'small',
],
[
'name' =>'Jack',
'house' => null,
],
];
var_dump(array_column($array,null,'house'));
On 5.6.30, 7.0.0, 7.2.0 (not limited to) get the following results
array(3) {
["big"]=>
array(2) {
["name"]=>
string(3) "Bob"
["house"]=>
string(3) "big"
}
["small"]=>
array(2) {
["name"]=>
string(5) "Alice"
["house"]=>
string(5) "small"
}
[0]=>
array(2) {
["name"]=>
string(4) "Jack"
["house"]=>
NULL
}
}
The new index, null will be converted to int, and can be incremented according to the previous
index, that is, if Alice "house" is also null, then Alice's new index is
"0", Jack's new index is "1"
On 7.1.21, 7.2.18, 7.4.8 (not limited to) will get the following results
array(3) {
["Big"]=>
array(2) {
["name"]=>
string(3) "Bob"
["house"]=>
string(3) "Big"
}
["small"]=>
array(2) {
["name"]=>
string(5) "Alice"
["house"]=>
string(5) "small"
}
[""]=>
array(2) {
["name"]=>
string(4) "Jack"
["house"]=>
NULL
}
}
The new index null will be converted to an empty string
----
Server IP: 45.112.84.4
Probable Submitter: 103.51.166.36 (proxied: 119.123.133.215)
----
Manual Page -- http://php.net/manual/en/function.array-column.php
Edit -- https://master.php.net/note/edit/125182
Del: integrated -- https://master.php.net/note/delete/125182/integrated
Del: useless -- https://master.php.net/note/delete/125182/useless
Del: bad code -- https://master.php.net/note/delete/125182/bad+code
Del: spam -- https://master.php.net/note/delete/125182/spam
Del: non-english -- https://master.php.net/note/delete/125182/non-english
Del: in docs -- https://master.php.net/note/delete/125182/in+docs
Del: other reasons-- https://master.php.net/note/delete/125182
Reject -- https://master.php.net/note/reject/125182
Search -- https://master.php.net/manage/user-notes.php