If you have a PHP variable that is storing Boolean data, i.e.
0 for "false" or "no" and 1 for "true" or
"yes", but want to display the value as "no" when a zero is stored in the
variable and "yes" when a one is stored in the variable, you can print
the value using the ternary operator, ?, which is
described in the Ternary Operator section of the manual page
Comparison Operators.
E.g., suppose I have an array named swinfo that has
information on various software packages that has an
array variable Free that has a 0 stored in it
if the software is not free and a 1 stored in it if the
software is free. If I have a software package that isn't free, if I just
print the contents of the variable as in the first instance below, I get a
zero, but by using ther ternary operator, i.e., the ?, I can
specify that I want "yes" or "no" displayed, instead as for the
second instance where it is displayed below.
echo "<table>\n" .
"<tr>\n" .
"<td><b>Free:</b></td><td>" .
$swinfo['Free'] . "</td>" .
"</tr>\n" .
"<tr>\n" .
"<td><b>Free:</b></td><td>" .
($swinfo['Free'] ? 'yes' : 'no') . "</td>" .
"</tr>\n" .
"</table>\n";
For an instance where the software isn't free, I would see the following displayed:
| Free: | 0 |
| Free: | no |
References:
