PHP Function to get First 5 Values of array PHP Function to get First 5 Values of array php php

PHP Function to get First 5 Values of array


Use array_slice() function:

$newArray = array_slice($originalArray, 0, 5, true);


If you need the first 5 elements

before the array_slice(). Insert a letter 'r' to the second place for reverse order: krsort(), arsort().