How can an array be used in PHP to exclude certain numbers from being randomly selected?
When generating random numbers in PHP, you can use an array to store the numbers that you want to exclude from the random selection. One way to achieve this is by generating a random number, checking if it is in the exclusion array, and if it is, generating a new random number until a valid one is found. This ensures that the excluded numbers are not included in the random selection.
$excludedNumbers = [5, 10, 15]; // Numbers to exclude from random selection
do {
$randomNumber = rand(1, 20); // Generate a random number between 1 and 20
} while (in_array($randomNumber, $excludedNumbers));
echo "Random number selected: $randomNumber";