Limit array to 5 items

You can use the "array_slice" function in PHP to limit an array to a specific number of items. For example, to limit an array to 5 items, you can use the following code:

<?php

$array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
$limitedArray = array_slice($array, 0, 5);

print_r($limitedArray);

Watch a course Learn object oriented PHP

This will create a new array called "limitedArray" that contains the first 5 items from the original array.