I have an array containing the numbers 1 to 10. When i select one random array key, i want to delete this one The following code does something like it, but just not good enough.
$imgArray = range(1,9);
$rand_key = array_rand($imgArray);
$imgValue = $imgArray[$rand_key];
unset($imgArray[$imgValue]);
The code deletes a value from the array, but it deletes the wrong one, Echoing the array gives the following result:
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 6
[6] => 7
[7] => 8
[8] => 9
)
Random selected item would be like number 4 but then it deletes array KEY 4, not array value 4..
Is there any way to change that? besides changing the variable(using -1)?