php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41469 err number key in array_slice
Submitted: 2007-05-23 08:55 UTC Modified: 2007-05-23 10:20 UTC
From: fallseir at gmail dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.2.2 OS: linux
Private report: No CVE-ID: None
 [2007-05-23 08:55 UTC] fallseir at gmail dot com
Description:
------------
在数字和字母混合的键值数组中 数字key被重新排列了
use array_slice
array keys for number and string
the result is err!

Reproduce code:
---------------
$thisArray=array(1=>0,2=>31,"a9"=>1,"0"=>3,"abc"=>20);
print_r($thisArray);
$a2=array_slice($thisArray,0,100);
print_r($a2);

Expected result:
----------------
Array
(
    [1] => 0
    [2] => 31
    [a9] => 1
    [0] => 3
    [abc] => 20
)
Array
(
    [1] => 0
    [2] => 31
    [a9] => 1
    [0] => 3
    [abc] => 20
)

Actual result:
--------------
Array
(
    [1] => 0
    [2] => 31
    [a9] => 1
    [0] => 3
    [abc] => 20
)
Array
(
    [0] => 0
    [1] => 31
    [a9] => 1
    [2] => 3
    [abc] => 20
)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-05-23 10:20 UTC] scottmac@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

array_slice resets numeric keys as it states in the manual, the fourth parameter can be used to preserve keys.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Tue Oct 06 07:00:02 2026 UTC