Browse Source

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
nate 19 years ago
parent
commit
3c669d7cee
1 changed files with 14 additions and 0 deletions
  1. 14 0
      cake/basics.php

+ 14 - 0
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;
+	}
 ?>