PHP abreviación del condicional IF/Else
Hagámoslo sencillo:
La forma ordinaria:
if (condicional) {
$variable = "devuelve esto si es verdad";
}
else {
$variable = "devuelve esto si es falso";
}
La forma corta:
$variable = (condicional) ? "devuelve esto si es verdadero" : "devuelve esto si es falso";
Y esto es como funciona: condicional ? si-verdad : si-falso
Home
mayo 29th, 2009 at 13:59
It’s hard to find a lot of information on this (and if there are other similar statements), but I noticed that it’s more formally known as a ternary statement! http://en.wikipedia.org/wiki/Ternary_operation