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

Tolal:0 Click:

Show All Comments

Did not find what you were looking for leave your name and message. We will revert within 24 hours
Name:
eMail:
Comment / Feedback: