note 106063 added to function.array-slice
| From: | mdessaintes at gmail dot com | Date: | Thu, 06 Oct 2011 22:29:38 +0000 |
| Subject: | note 106063 added to function.array-slice | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-183695@lists.php.net to get a copy of this message | ||
Pay attention that this function use the offset and not the index of the array.
So if you create a numeric indexed array like this:
$arr[2] = 2;
$arr[1] = 1;
$arr[0] = 0;
And then you use array_slice:
$slice = array_slice($arr,0,3);
var_dump($slice);
/*
array
0 => int 2
1 => int 1
2 => int 0
=> This is not the first three elements (index 0, 1 and 2) of the array but the first three in
"array memory" (like the order get using foreach on the array)
*/
$slice = array_slice($arr,0,1);
var_dump($slice);
/*
array
0 => int 2
*/
----
Server IP: 69.147.83.197
Probable Submitter: 80.236.234.38
----
Manual Page -- http://www.php.net/manual/en/function.array-slice.php
Edit -- https://master.php.net/note/edit/106063
Del: integrated -- https://master.php.net/note/delete/106063/integrated
Del: useless -- https://master.php.net/note/delete/106063/useless
Del: bad code -- https://master.php.net/note/delete/106063/bad+code
Del: spam -- https://master.php.net/note/delete/106063/spam
Del: non-english -- https://master.php.net/note/delete/106063/non-english
Del: in docs -- https://master.php.net/note/delete/106063/in+docs
Del: other reasons-- https://master.php.net/note/delete/106063
Reject -- https://master.php.net/note/reject/106063
Search -- https://master.php.net/manage/user-notes.php