the values of the array are displayed on a page (in a hidden div) using the heredoc declaration with an if to check if the checkbox has been used - if the return is empty the div does not show - if one of the checkboxes is "checked" then it does.
In PHP there are three types of strings
- Single quoted - string gets dumped as is - no parsing of string - single quotes escaped with a \ double quotes allowed as is.
- Double quoted - strings are parsed and variables (optionally enclosed in {}) are replaced with their values. Double quotes escaped with a \ single quotes allowed as is
- HEREDOC - tag enclosed string - allows mixing of single and double quotes without escaping and does variable substitution.
In your example ('$cheesebox') is interpreted as a string - not its value - take the single quotes from around the variable.
You are not showing us where $cheesebox is being set - so we cannot see if your use of the if statement is correct or not.
Alternative to the if is the switch statement
switch ($cheesebox) { case 'Cheddar' : // Handle Cheddar break; case 'Gouda' :// Handle Gouda break; case 'Bleu':// Handle Bleu break; default: // Handle default here (when none of the above match) break;}
Both of these examples work - they display the echo associated to the value name - this is based on what both Ray and Julian wrote.... I'm leaning toward the first as I can then add other divs around that particular echo.
if ($cheesebox == "Cheddar") {
echo "Your topping is Cheddar";
} else if ($cheesebox == "Gouda") {
echo "Your topping is Gouda";
} else if ($cheesebox == "Bleu") {
echo "Your topping is Bleu";
}
if (in_array($cheesebox, ['Cheddar', 'Gouda', 'Bleu'])) {
echo "Your side order is {$cheesebox}";
}
The single and double quotes from what I understood was (in my mind) looking for a literal value in '$cheesebox' then comparing it to whatever that was in == ""
I guess I got that round wrong
I am still on the same thing now - even though the echo works - its outside of the heredoc OUTPUT4 and throws the echo to the top of the page. Can this work inside the OUTPUT4?
I've never worked with the heredoc class before, so if this seems rudimentary, please be lenient with me...
Here's some background information on how we handle checkboxes.
https://www.experts-exchange.com/articles/5450/Common-Sense-Examples-Using-Checkboxes-with-HTML-JavaScript-and-PHP.html
Also, it looks as if you may be using some kind of CMS or framework. If so, please tell us what it is, thanks.