|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-02-04 16:43 UTC] ajaydixit91 at gmail dot com
Description: ------------ --- From manual page: http://www.php.net/function.array-slice#refsect1-function.array-slice-description --- I encountered this bug in array_slice() function. Here is what i encountered. I declared an array "my_array" with different offset value. In my case its offset value is 1. So my_array[0] is not defined. Now when I After that, i used the predefined function array_slice. In array_slice i entered 1 and 3 as the offset value and required length value. Now as print the sliced array, it should display: shiva hanu bhrama but what i am experiencing is : vishnu shiva hanu. It seems like that the array_slice function is not aware of the offset value change in the array. Test script: --------------- <?php $my_array = array( 1 => "vishnu" , "shiva" , "hanu" , "bhrama" ); print_r($my_array); echo $my_array[0]; // this is coming undefined // $slice = array_slice($my_array,1,3); print_r($slice); ?> PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 06:00:02 2025 UTC |
In your example, the fact that you have instructed the array to begin at offset 1 has no bearing on the result of the call to array_slice, observe: <?php $my = array("other", "vishnu" , "shiva" , "hanu" , "bhrama" ); print_r($my); print_r(array_slice($my, 1, 3)); ?> You are explicitly instructing the call to array slice to start at offset 1 (vishnu), and return three elements: vishnu shiva hanu is the only outcome possible regardless of the contents of an offset not referenced.