Hi Reader's,
Welcome to FindNerd, today we are going to discuss array_slice() in php ?
The array_slice() function is used to for returning selected parts of an array.
syntax of array_slice()
array_slice(array,start,length,preserve)
In the above given syntax array and start both are required parameter
and length and preserve both are option parameter
<?php
//here define a variable of array
$data = array(
'Emp_name' => 'Joe',
'Emp_age' => 40,
'Emp_dep' => 'account',
);
//here call array_slice() and pass starting point
print_r(array_slice($data,2));
//here pass start and length both
print_r(array_slice($data,1,2));
?>
output will come following of above example
when you will pass only start parameter
Array ( [Emp_dep] => account )
and when you will pass start and length both parameter
Array ( [Emp_age] => 40 [Emp_dep] => account )
0 Comment(s)