Can someone please explain to me the use of alternative syntax I often come across when looking at php usage in word press. Take conditionals for example:
I expect to see:
if(10==10)
echo 'this is true and will be shown';
Instead, I see:
if(10==10):
echo 'this is true and will be shown;
end if;
And another example:
! empty ( $classes_names )
and $class_names = ' class="'. esc_attr( $class_names ) . '"';
Whats with the ‘:’ the ‘end if;’ and the last examples syntax is not something I have seen before put together like that.
This is the alternative logic syntax in PHP – you can read all about it here – http://php.net/manual/en/control-structures.alternative-syntax.php
If you are including conditional statements in amongst HTML or other code then it makes things look a lot neater.
For example:
Looks much nicer IMO as:
As for the final code example – this is another way of writing an if statement – so this:
Is the same as:
That is definitely confusing for sure!