Sub array from a big array
I need to get a sub array from a big array (i dont know the array, it comes from the database), like this:
$array =
ar开发者_运维技巧ray(0=>'Name 1',1=>'Name 2',2=>'Name 3',3=>'Name 4',4=>'Name 5',5=>'Name 6');
What i need is to get the first 3 elements.
$new_array = array(0=>'Name 1',1=>'Name 2',2=>'Name 3');
Thanks!
$new_array = array_slice( $array, 0, 3);
you could also try array_chunk()
to separate your array into small ones
精彩评论