How to implement and used array slice function in php

Description

What is array slice function in php and how to implement array_slice() function. Array slice parameters, syntax and with example.How to find starting position and slice length in array with single function array. Definition of array_splice() Function and with Syntax in PHP

Syntax Overview

array_slice function in php with example and syntax

The array slice function returns the Specifies position of elements.

Check Syntax array_slice() function: 

array_slice(array_name set, starting_position set, slice_length set, preserve_keys set) 

For example

$color_list = array('Red','green','blue','orange');  

$resultout= array_slice($color_list,3);  

print_r($resultout);  

echo "<br>";  

$result= array_slice($color_list,-2,1);  

print_r($resultout);  

echo "</br>";  

$result= array_slice($color_list,0,4);  

print_r($resultout); 

$result= array_slice($color_list,0,2);  

print_r($resultout);

First Output : orange (Show 3rd position of array elements.)

2nd output : Blue (Show 2nd position of array elements.)

3rd output : Red, green, blue, orange. (Show all 0 to 4 position of array elements.)

4th output : Red, green. (Show 0 to 2 position of array elements.)