PHP conditionals, brackets needed?

you can do if else statements like this: <?php if ($something) { echo ‘one conditional line of code’; echo ‘another conditional line of code’; } if ($something) echo ‘one conditional line of code’; if ($something) echo ‘one conditional line of code’; echo ‘a NON-conditional line of code’; // this line gets executed regardless of the … Read more

Conditional comment for ‘Except IE8’?

there’s some JS that I want to load for all browsers EXCEPT IE8, what conditional comment should I use? For something to appear in ‘other browsers’ that don’t support CCs, you need a downlevel-revealed conditional comment. <!–[if !IE 8]><!–> …. <!–<![endif]–> (this is slightly different to Microsoft’s official syntax which is not valid HTML.) “All … Read more

Conditional with statement in Python

Python 3.3 and above Python 3.3 introduced contextlib.ExitStack for just this kind of situation. It gives you a “stack”, to which you add context managers as necessary. In your case, you would do this: from contextlib import ExitStack with ExitStack() as stack: if needs_with(): gs = stack.enter_context(get_stuff()) # do nearly the same large block of … Read more

PHP – and / or keywords

and and or have higher lower precedence than && and ||. To be more exact && and || have higher precedence than assignment operator ( = ) while and and or have lower. http://www.php.net/manual/en/language.operators.precedence.php Usually it doesn’t make a difference, but there are cases when not knowing about this difference can cause some unexpected behaviour. … Read more