I have this code:
if (isset($array[$a]['estado']))
{
echo "True";
}
else
{
echo "False";
}
I want to know if I can pass it to the conditional format ? :
I have this code:
if (isset($array[$a]['estado']))
{
echo "True";
}
else
{
echo "False";
}
I want to know if I can pass it to the conditional format ? :
To give you a little more information, what you're looking for is called ternary operators and yes, they can be done in PHP.
These ternary operators work in the following way:
condicion ? resultadoTrue : resultadoFalse
Therefore, translating your if
, as commented @Muriano
, would be:
echo isset($array[$a]['estado']) ? "True" : "False"
If you have a version of PHP 5.3 or higher, you could delete the intermediate part of the ternary operator, leaving:
condicion ?: resultadoFalse
And it would return the value of condicion
if true or resultadoFalse
in case the condition was false.
echo isset($array[$a]['estado']) ? "True" : "False";