PHP Programing language

array_slice() Function in PHP
Previous Home Next

array_slice()

The array_slice() function returns selected parts of an array.

Syntax:
array_slice(array,start,length,preserve)

In above syntax, "array" specifies an array, "start" specifies the numeric value where the function will start the slice, "length" specifies the length of the returned array and "preserve" specifies if the function should preserve or reset the keys and key values are as follows:

  • true: Preserve keys
  • false - Default. Reset keys

 

Example:

<?php
$a=array("Apple","Mango","Orange","Papaya","Banana");
print_r(array_slice($a,1));
?>

Output:

Array ( [0] => Mango [1] => Orange [2] => Papaya [3] => Banana )

Previous Home Next