-
-
Save ramsey/da33c07d95bfd58ea29a to your computer and use it in GitHub Desktop.
array_column() null index key bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$a = [ | |
['a' => 10], | |
['a' => 20], | |
['a' => null], | |
['a' => null], | |
]; | |
$b = [ | |
['a' => 'foo'], | |
['a' => 'bar'], | |
['a' => null], | |
['a' => null], | |
]; | |
$c = [ | |
['a' => 10], | |
['a' => 20], | |
['a' => null], | |
['a' => null], | |
['a' => 'foo'], | |
['a' => 'bar'], | |
['a' => null], | |
['a' => null], | |
]; | |
var_export(array_column($a, null, 'a')); | |
echo "\n\n"; | |
var_export(array_column($b, null, 'a')); | |
echo "\n\n"; | |
var_export(array_column($c, null, 'a')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
array ( | |
10 => | |
array ( | |
'a' => 10, | |
), | |
20 => | |
array ( | |
'a' => 20, | |
), | |
21 => | |
array ( | |
'a' => NULL, | |
), | |
22 => | |
array ( | |
'a' => NULL, | |
), | |
) | |
array ( | |
'foo' => | |
array ( | |
'a' => 'foo', | |
), | |
'bar' => | |
array ( | |
'a' => 'bar', | |
), | |
0 => | |
array ( | |
'a' => NULL, | |
), | |
1 => | |
array ( | |
'a' => NULL, | |
), | |
) | |
array ( | |
10 => | |
array ( | |
'a' => 10, | |
), | |
20 => | |
array ( | |
'a' => 20, | |
), | |
21 => | |
array ( | |
'a' => NULL, | |
), | |
22 => | |
array ( | |
'a' => NULL, | |
), | |
'foo' => | |
array ( | |
'a' => 'foo', | |
), | |
'bar' => | |
array ( | |
'a' => 'bar', | |
), | |
23 => | |
array ( | |
'a' => NULL, | |
), | |
24 => | |
array ( | |
'a' => NULL, | |
), | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
array ( | |
10 => | |
array ( | |
'a' => 10, | |
), | |
20 => | |
array ( | |
'a' => 20, | |
), | |
'' => | |
array ( | |
'a' => NULL, | |
), | |
) | |
array ( | |
'foo' => | |
array ( | |
'a' => 'foo', | |
), | |
'bar' => | |
array ( | |
'a' => 'bar', | |
), | |
'' => | |
array ( | |
'a' => NULL, | |
), | |
) | |
array ( | |
10 => | |
array ( | |
'a' => 10, | |
), | |
20 => | |
array ( | |
'a' => 20, | |
), | |
'' => | |
array ( | |
'a' => NULL, | |
), | |
'foo' => | |
array ( | |
'a' => 'foo', | |
), | |
'bar' => | |
array ( | |
'a' => 'bar', | |
), | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment