From 3c669d7cee028561e0ac5dd11dbe2d23bb6f287e Mon Sep 17 00:00:00 2001 From: nate Date: Tue, 30 Jan 2007 16:34:22 +0000 Subject: [PATCH] Adding ternary op wrapper function to basics git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4349 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/basics.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cake/basics.php b/cake/basics.php index 14a59cd95..54664689c 100644 --- a/cake/basics.php +++ b/cake/basics.php @@ -1487,4 +1487,18 @@ return false; } } +/** + * Wraps ternary operations. If $condition is a non-empty value, $val1 is returned, otherwise $val2. + * + * @param mixed $condition Conditional expression + * @param mixed $val1 + * @param mixed $val2 + * @return mixed $val1 or $val2, depending on whether $condition evaluates to a non-empty expression. + */ + function ife($condition, $val1 = null, $val2 = null) { + if (!empty($condition)) { + return $val1; + } + return $val2; + } ?> \ No newline at end of file