note 106063 deleted from function.array-slice by tularis

From: Date: Fri, 07 Oct 2011 12:09:19 +0000
Subject: note 106063 deleted from function.array-slice by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-183703@lists.php.net to get a copy of this message
Note Submitter: mdessaintes at gmail dot com Reason: bad code ---- 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 */

« previous php.notes (#183703) next »