Hi,
I’ve been playing around with a module and some snippets learning how modx works. I can usually figure out what most of the code is doing but now I’m a bit stumped...
In this code: ’ $items = (isset($items)) ? intval($items) : -1; ’ can someone explain what the ’ : ’ means.
I’ve looked in the Php refrence manual but can’y find any thing there. I’m guessing it means something like ’or’, would that be right?
Thanks
-
☆ A M B ☆
- 24,524 Posts
that is the ternary operator. If the part before the ? is true, then the first part after the ? and before the : will be used, while if it is false then the part after the : will be used.
http://il2.php.net/operators.comparison
In the example you gave, it the variable $items is set then the integer value of $items used, if it’s not set then -1 is used. An if-else block could also be used, but once you learn to read these they become second nature.