note 62525 deleted from control-structures by nlopess
| From: | nlopess@php.net | Date: | Tue, 30 Jan 2007 19:09:14 +0000 |
| Subject: | note 62525 deleted from control-structures by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-122374@lists.php.net to get a copy of this message | ||
Note Submitter: administrador(ensaimada)sphoera(punt)com
----
The ternary conditional operator is sometimes unreadable and difficult to mantain.
For those users that don't like it (like me), another chance is:
<?php
// syntax based on IIF(...) pascal / Firefox / HB++ / Coldfusion operator
function iif($condition,$val_if_true,$val_if_false=""){
if ($condition)
return $val_if_true;
else
return $val_if_false;
}
$condition=true;
echo ($condition)?"it's true":"it's false";
// is the same that
echo iif($condition,"It's true","It's false");
// I think that the second one is easier to understand
?>
more functions at http://www.sphoera.com