|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-06-14 15:14 UTC] rele at gmx dot de
[2007-06-18 16:53 UTC] iliaa@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 28 04:00:01 2025 UTC |
Description: ------------ array_slice supports omitting of the $length parameter only if you pass just the first two parameters (params 1 and 2), but passing the default value NULL when you want to set $preserve_keys to TRUE (params 1, 2, 3 and 4) does not work. This would be especially useful for associative arrays. Reproduce code: --------------- $a = array(1,2,3); $b = array('a'=>1,'b'=>1,'c'=>2); var_dump(array_slice($a, 1), array_slice($a, 1, 2, TRUE), array_slice($a, 1, NULL, TRUE), array_slice($b, 1), array_slice($b, 1, 2, TRUE), array_slice($b, 1, NULL, TRUE)); Expected result: ---------------- array(2) { [0]=> int(2) [1]=> int(3) } array(2) { [1]=> int(2) [2]=> int(3) } array(2) { [1]=> int(2) [2]=> int(3) } array(2) { ["b"]=> int(1) ["c"]=> int(2) } array(2) { ["b"]=> int(1) ["c"]=> int(2) } array(2) { ["b"]=> int(1) ["c"]=> int(2) } Actual result: -------------- array(2) { [0]=> int(2) [1]=> int(3) } array(2) { [1]=> int(2) [2]=> int(3) } array(0) { } array(2) { ["b"]=> int(1) ["c"]=> int(2) } array(2) { ["b"]=> int(1) ["c"]=> int(2) } array(0) { }