3v4l.org

run code in 500+ PHP versions simultaneously
<?php $data['slider'] = [1,2,3,4,5,6,7,8,9]; $sliced_array = array_slice($data["slider"], 0, 3); var_export($sliced_array); // preserving the keys is useless echo "\n***\n"; // Shuffle the keys and loop through them to create a new, randomized array of images. shuffle($sliced_array); var_export($sliced_array); // reordered elements are reindexed echo "\n***\n"; $data['slider'] = $sliced_array + array_slice($data["slider"], 0); // starting slice from zero is the default, so the parameter is not needed var_export($data);

preferences:
49.57 ms | 1144 KiB | 5 Q