|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68553 array_column: null values in $index_key become incrementing keys in result
Submitted: 2014-12-05 16:46 UTC Modified: -
Avg. Score:3.7 ± 0.9
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:1 (33.3%)
From: Assigned:
Status: Closed Package: Arrays related
PHP Version: 5.6.3 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
New email:
PHP Version: OS:


 [2014-12-05 16:46 UTC]
When using $index_key to index the resulting array by a column from the original array, if null values are encountered, the resulting keys become integer values that are auto-incremented according to the previous integer key value (or start from 0, as a 0-indexed key).

Test script with actual result and expected result is available here:

Jan Roald Haugland first reported this issue on my blog:

Test script:
See link to gist.

Expected result:
NULL keys should be converted to empty strings, and multiple matching keys should be overwritten by the last value entered for that key.

For example:

$foo = [
    null => 1,
    null => 2,
    null => 3


    '' => 3

Actual result:
With array_column(), NULL keys are being converted to 0-indexed integer key values, incrementing.

So an array that gets evaluated to this and, therefore, should result in the expected array shown above:

    null => 1,
    null => 2,
    null => 3

ends up resulting in this:

    0 => 1,
    1 => 2,
    2 => 3

See link to gist for full example and actual output.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-12-05 17:22 UTC]
As a side note, I tested this on HHVM 3.4.0, and it properly produces the expected output, so we need to fix PHP's engine to produce the same expected output.
 [2014-12-06 00:15 UTC]
My array_column polyfill library also behaves as expected on earlier versions of PHP (specifically tested the example script on 5.3.29):
 [2018-07-24 03:37 UTC]
Automatic comment on behalf of
Log: Fixed bug #68553 (array_column: null values in $index_key become incrementing keys in result)
 [2018-07-24 03:37 UTC]
-Status: Open +Status: Closed
 [2021-10-04 23:46 UTC] lemon dot head dot bw+bugs-php-net at gmail dot com
Especially frustrating if subsequent explicit items overwrite previous auto-increment items.
Typical example would be doing this with token_get_all().
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jul 16 12:01:28 2024 UTC