Usagae of “array_slice” function

Usagae of “array_slice” function

Usagae of “array_slice” function
========================
  array_slice
  
   It extract a slice of the array

Syntax:
======
  array array_slice ( array array, int offset [, int length])

Description:
=========
  
  array_slice() returns the sequence of elements from the array array as specified by the offset and length parameters.

 If offset is positive, the sequence will start at that offset in the array. If offset is negative, the sequence will start that far from the end of

the array.

 If length is given and is positive, then the sequence will have that many elements in it. If length is given and is negative then the sequence

will stop that many elements from the end of the array. If it is omitted, then the sequence will have everything from offset up until the end of the

array.

 

Example:
=======
 $input = array (”a”, “b”, “c”, “d”, “e”);

 $output = array_slice ($input, 3);     

   it extracts from the 3rd element of the array. It returns  “d”, and “e”

 $output = array_slice ($input, 2, -1); 

   it extracts from the 2nd element upto (last-1) element of the array. It returns  “c”, and “d”

 $output = array_slice ($input, -2, 1); 

   it extracts one elements from the (last-2)  position of the array. It returns  “d”

 $output = array_slice ($input, -4, 2);  

   it extracts two elements from the (last-4)  position of the array. It returns  “b”, and “c”.
 

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.