If you need to preserve the original array you can use the function array_diff()
to create a copy with the value of $current
removed:
$temparray = array_diff($randomarray, [$current]);
If you don't need to preserve the original array use the function unset()
to remove the value of $current
:
unset($randomarray[$current]);
Note that array_diff()
returns the result of the operation as a new array, so you must assign it to a variable, whereas unset()
modifies the array in-place.
Either way, you can then pick a random index with the function array_rand()
and use that index to get the value:
$i = array_rand($array);
echo $array[$i];
Replace $array
with the correct array variable (either $temparray
or $randomarray
).