How can a while loop be used in PHP to display all colors when a specific option is selected?
To display all colors when a specific option is selected, you can use a while loop in PHP to iterate through an array of colors and output them one by one. You can use an if statement to check if the specific option is selected, and then use the while loop to display all colors.
$colors = array("Red", "Blue", "Green", "Yellow");
if(isset($_POST['selected_option']) && $_POST['selected_option'] == 'all_colors') {
$i = 0;
while($i < count($colors)) {
echo $colors[$i] . "<br>";
$i++;
}
}