I was wondering if there was any way to perform a ternary codicional that only evaluates a true condition and not a false one.
For example, the ternary conditional in php would be:
$n = (2) ? true : false;
My idea would be to make a ternary conditional such that:
$n = (2) ? true;
I have tried different ways but they all give me an error, so I guess there is no way, but just in case I ask around here.
Thanks! :)
I put the entire code without the previous example:
function encrypt($chr) {
if($chr === 'Ñ') { return 0; }
$abc = array( 'A' => 2, 'B' => 22,
'C' => 222, 'D' => 3,
'E' => 33, 'F' => 333,
'G' => 4, 'H' => 44,
'I' => 444, 'J' => 5,
'K' => 55, 'L' => 555,
'M' => 6, 'N' => 66,
'O' => 666, 'P' => 7,
'Q' => 77, 'R' => 777,
'S' => 7777, 'T' => 8,
'U' => 88, 'V' => 888,
'W' => 9, 'X' => 99,
'Y' => 999, 'Z' => 9999 );
return $abc[$chr];
}
My idea was simply to use a ternary instead of an if, (for aesthetics) I know it's silly. That's why I was wondering if you could do something like:
return $chr == 'Ñ' ? true : false;
The thing is that I only want to return the true, not the false, if it's false, my idea is to continue with the code.