Yes it is possible but DO not do ternary chaining in PHP because it makes the evaluations of the expression from the left different from most languages which in practice returns strange results (the middle one) perceive that the other answers made the thread but always with parentheses to set the priority.
Example of ternary that returns the result of the medium:
$ativo = 1;
$r = $ativo == 0 ? 'Médico(a) Desativado(a)' :
$ativo == 1 ? 'Médico(a) Ativo(a)' :
$ativo == 2 ? 'Outro' : 'else final';
echo $r;
The output: Outro
To fix this side effect , in PHP 5.3 the elvis operator ( ?:
) was introduced, it returns the first or last part of the expression. The simplest way I see is to do an array with status:
$descricao = array(0 => 'Médico(a) Desativado(a)', 1 => 'Médico(a) Ativo(a)', 2 =>'Outro');
$ativo = 5;
echo $descricao[$ativo] ?: 'Resultado padrão';
In PHP 7 you can use null coalescing ( ??
):
echo $descricao[$ativo] ?? 'Resultado padrão';