Extracting a Portion of an Array: array array_slice(array $array, int $offset[, int $length[, bool $preserve]] ) : array_slice « Data Structure « PHP






Extracting a Portion of an Array: array array_slice(array $array, int $offset[, int $length[, bool $preserve]] )

 
<?php 
$languages = array( 'French', 'German', 'Russian', 'Chinese'); 
printf("<pre>Original array:\n%s</pre>\n", var_export($languages, TRUE)); 

$slice1 = array_slice($languages, 2, count($languages) - 2); 

printf("<pre>Slice 1:\n%s</pre>\n", var_export($slice1, TRUE)); 

$slice2 = array_slice($languages, 2, count($languages) - 2, TRUE); 

printf("<pre>Slice 2:\n%s</pre>\n", var_export($slice2, TRUE)); 
?>
  
  








Related examples in the same category

1.array_slice
2.Extract a slice of the array