Please I need some help. I have the array given below and I want to return random elements from it.
$data = array('Computer', 'Laptop', 'Mouse', 'Keyboard');
$rand = rand(0,count($data)-1);
echo $data[$rand];
The code above works as expected. However, I wan't to be able to exclude specific elements from the returned list as given below:
$exclude = "Mouse";
$data = array('Computer', 'Laptop', 'Mouse', 'Keyboard');
$rand = rand(0,count($data)-1);
echo $data[$rand];
The expected result is that the element specified in $exclude "Mouse" in this case will not be returned as one of the random elements.
Maybe the mouse element will first be removed from the array as seen below then a random element will be returned:
$data = array('Computer', 'Laptop', 'Keyboard');
rand()add mouse with or without key.