PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hello .. I was able to do this in VB so .. I am sure I can do it in PHP .... anyway how do you write an if else statement or switch statment so you accomplish the following
if ($var == "xyz") {
// tons of code or call to function
echo($htmlcode);
} else {
// tons of different code or function
echo ($htmlcode);
}
Basic PHP. Switch is used for an if then elseif ... structure (CASE I believe in VB).
I tried something similar to what you wrote .. but I am getting a parsing error .. I think because I am trying to dynamically write other stuff as well
You need to break out of your code, but essentially what you want to do will work fine - but before all the "=== write this code" stuff, break out of PHP first.
<?php if ( $something_is_true ) : ?>
...lots of HTML....
<?php else: ?>
...lots of HTML....
<?php endif; ?>
I find using that method nice when mixing PHP with HTML. The endif; is clearer than a }, because with a } you don't know what it's being used for without some checking. The endif; makes it clear. So if you are mixing a few block level elements like a foreach, a while and an if, it makes reading easier.