#15520 [Ver->Opn]: array_slice destroys numeric keys
| From: | sniper@php.net | Date: | Tue, 15 Oct 2002 00:26:26 +0000 |
| Subject: | #15520 [Ver->Opn]: array_slice destroys numeric keys | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-22416@lists.php.net to get a copy of this message | ||
ID: 15520
Updated by: sniper@php.net
Reported By: david@acz.org
-Status: Verified
+Status: Open
Bug Type: Feature/Change Request
Operating System: Linux
PHP Version: 4.3.0-dev
Previous Comments:
------------------------------------------------------------------------
[2002-07-03 21:16:38] eru@php.net
Got me convinced: re-categorizing, -versioning, etc.
------------------------------------------------------------------------
[2002-07-03 20:29:07] david@acz.org
This is a bug. Or at least, it is a very serious documentation
problem. The function is taking the slices correctly. But it is
destroying numeric keys, and leaving non-numeric keys alone. Why does
it arbitrarily change keys that happen to be numeric? Array keys are
not based on numbers, so array_slice should not be concerned with their
actual value, especially if it is using the actual element positions to
calculate the slice.
------------------------------------------------------------------------
[2002-07-03 20:06:40] eru@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
From the manual-page:
Note that array_slice() will ignore array keys, and will calculate
offsets and lengths based on the actual positions of elements within
the array.
------------------------------------------------------------------------
[2002-02-12 08:59:34] david@acz.org
The array_slice function destroys keys that are numeric (even if used
as strings), but not string keys. This is a serious bug, which makes
the function unusable. I had to write my own function to correctly
take the slice of an array. If this is indeed intended behavior, then
it should be noted as such in the manual, and a new function added to
take array slices that does not destroy numeric keys.
<?
$a = array("7" => "foo", "f" => "bar",
"13" => "blah");
print_r($a);
print_r(array_slice($a, 0));
?>
Array
(
[7] => foo
[f] => bar
[13] => blah
)
Array
(
[0] => foo
[f] => bar
[1] => blah
)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=15520&edit=1