|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 06 15:00:01 2026 UTC |
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));