|
|
Php Array Elements Slice Function
|
Tutorials » Php »
|
Topic |
What is array_slice Function?
|
|
Explanation |
|
The "array_slice" function is used to slice 0r extract elements from the array
Syntax:
array_slice(array,start,length,preserve)
In the above syntax "array" specifies the array,"start" specifes where the function will start to splice,
"length" specifes the total length of the slice, "preserve" if "true" else it will reset keys.
Example
<?php
$b=array( 0 =>"Cherry",1 =>"Strawberry", 2 =>"Apple", 3 => "Orange");
print_r(array_slice($b,1,2));
?>
Result:
Array ( [1]=> Strawberry, [2]= Apple);
In the above example the array is sliced from the first element to length of second elements length totally.
|
|
A Note |
Learn PHP programming language tutorial with simple and neat example. Hope you enjoy this free tutorial.
Do give us your valuable feedback and suggestions on this online tutorial. This is a Copyright Content.
|
|
|
|