php.net |  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
Votes:1
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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jesushuertaarrabal at gmail dot com
New email:
PHP Version: OS:

 

 [2014-11-16 18:20 UTC] jesushuertaarrabal at gmail dot com
Description:
------------
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)

Patches

Pull Requests

History

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] requinix@php.net
-Status: Closed +Status: Not a bug
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 13:01:33 2025 UTC