Bug #68429 [Csd->Nab]: array_fill_keys function deletes repeated keys
| From: | requinix@php.net | Date: | Sun, 16 Nov 2014 22:52:04 +0000 |
| Subject: | Bug #68429 [Csd->Nab]: array_fill_keys function deletes repeated keys | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-188625@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=68429&edit=1
ID: 68429
Updated by: requinix@php.net
Reported by: jesushuertaarrabal at gmail dot com
Summary: array_fill_keys function deletes repeated keys
-Status: Closed
+Status: Not a bug
Type: Bug
Package: Arrays related
PHP Version: 5.6.3
Block user comment: N
Private report: N
Previous Comments:
------------------------------------------------------------------------
[2014-11-16 19:53:19] jesushuertaarrabal at gmail dot com
associative arrays must have a unique key.
------------------------------------------------------------------------
[2014-11-16 19:24:53] 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 18:20:28] 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)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=68429&edit=1