I want to return first 5 items from array. How can I do this?
array_splice — Remove a portion of the array and replace it with something else:
$input = array(1, 2, 3, 4, 5, 6); array_splice($input, 5); // $input is now array(1, 2, 3, 4, 5)
From PHP manual:
array array_splice ( array &$input , int $offset [, int $length = 0 [, mixed $replacement]])
If length is omitted, removes everything from offset to the end of the array. If length is specified and is positive, then that many elements will be removed. If length is specified and is negative then the end of the removed portion will be that many elements from the end of the array. Tip: to remove everything from offset to the end of the array when replacement is also specified, use count($input) for length .