<?php $array = [ 'one', 'two', 'three', 'four' ]; $n = 10; $result = []; for ($x = 0; $x < $n; $x += (int) (!$x || $result[$x] !== $result[$x - 1])) { $result[$x] = $array[array_rand($array)]; } echo json_encode($result);
You have javascript disabled. You will not be able to edit any code.