I want the array to be sorted randomly, I made the condition that if there is such an element in the array, it is not added again, but for some reason it is added
<?php error_reporting(-1); $arr = [ 'African elephant', 'Spotted hyena', 'Snow leopard', ]; echo '<pre>'; var_dump($arr); echo '<pre>'; $new_arr = []; $count = count($arr); for($i = 0; $i < count($arr); $i++){ if (in_array($arr[$i], $new_arr)) { !array_push($new_arr, $arr[rand(0, count($arr)-1)]); } else{ array_push($new_arr, $arr[rand(0, count($arr)-1)]); } } var_dump($new_arr);
array_pushfunctionarray_pushall in this thread. - vp_arth