|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68429 array_fill_keys function deletes repeated keys
Submitted: 2014-11-16 18:20 UTC Modified: 2014-11-16 22:52 UTC
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: jesushuertaarrabal at gmail dot com Assigned:
Status: Not a bug 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:
From: jesushuertaarrabal at gmail dot com
New email:
PHP Version: OS:


 [2014-11-16 18:20 UTC] jesushuertaarrabal at gmail dot com
I was trying to associate values equals 1 for all the characters of a simple word with repeated characters with the function array_fill_keys.
For any reason I found that some keys were erased for any reason after using it like the example bellow.

Test script:
$word = 'metheor';
$arr = [];
echo strlen($word); //It shows the lenght of the word
for ($i = 0; $i < strlen($word); $i++){
  $arr[] = $word[$i];
print_r($arr); //It shows the full word
print_r(array_fill_keys($arr, 0)); //It shows the word filled with 0's but without repeated characters

Expected result:
array([m]=>1, [e]=>1, [t]=>1, [h]=>1, [e]=>1, [o]=>1, [r]=>1)

Actual result:
array([m]=>1, [e]=>1, [t]=>1, [h]=>1, [o]=>1, [r]=>1)


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-11-16 19:24 UTC] jesushuertaarrabal at gmail dot com
following with the issue investigation, I've just realiced that array_combine also cause the same issue:

Test script:
$word = 'metheor';
$arr = $arr_fill = [];
echo strlen($word);
for ($i = 0; $i < strlen($word); $i++){
  $arr[] = $word[$i];
  $arr_fill[] = 0;
print_r(array_combine($arr, $arr_fill));
 [2014-11-16 19:53 UTC] jesushuertaarrabal at gmail dot com
-Status: Open +Status: Closed
 [2014-11-16 19:53 UTC] jesushuertaarrabal at gmail dot com
associative arrays must have a unique key.
 [2014-11-16 22:52 UTC]
-Status: Closed +Status: Not a bug
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu Jun 30 21:05:47 2022 UTC