An assignment question reads as follow
I have created the function, as follows:
function getToppings($toppings){
if($toppings=='') {
echo 'You have to select at least one topping';
die();
}//if
foreach($toppings as $index => $selected) {
$toppings[$index] = $selected;
echo $selected;
echo '<br />';
}//foreach
}//function
HTML
Select Your Topping
<form name="select-topping" method="post">
<label for="toppings">Peperoni</label>
<input type="checkbox" name="toppings[]" value="peperoni">
<br />
<label for="toppings">Salami</label>
<input type="checkbox" name="toppings[]" value="salami">
<br />
<label for="toppings">Ham</label>
<input type="checkbox" name="toppings[]" value="ham">
<br >
<label for="toppings">Mushroom</label>
<input type="checkbox" name="toppings[]" value="mushroom">
<button type="submit" name="submit" class="btn btn danger">Submit</button>
</form>
Function Call
if(isset($_POST['submit'])){
getToppings($_POST['toppings']);
}
The functions works perfectly, and prints all toppings, selected, however my problem comes in when no toppings are selected (validation)
MY PROBLEM
When no topping is selected I get the following, error:
So eventhough my form validates, I still get the error undefined variable:
Now I am pretty sure I know why I get the error message, it is because if no toppings were selected, no parameters gets passed to function...correct? What I do not know is how to fix / improve on it...any advice or help appreciated.

