fixing last commit

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4496 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2007-02-10 08:14:01 +00:00
parent 2c837ffac2
commit 0fc79cdf6a

View file

@ -75,18 +75,27 @@ class Object{
return $class; return $class;
} }
/** /**
* Return a value from an array list. * Return a value from an array list if the key exists.
*
* If a coma separated $list is passed arrays are numeric with the key of the first being 0
* $list = 'no, yes' would translate to $list = array(0 => 'no', 1 => 'yes');
*
* If an array is used, keys can be strings example: array('no' => 0, 'yes' => 1);
*
* $list defaults to 0 = no 1 = yes if param is not passed
* *
* @param string $selected * @param string $selected
* @param array $list * @param mixed $list can be an array or a coma separated list.
* @return string the value of the array key * @return string the value of the array key or null if no match
*/ */
function enum($select, $list = array('no', 'yes')) { function enum($select, $list = array('no', 'yes')) {
$return = null; $return = null;
if(is_array($list)){ if(is_string($list)) {
if (array_key_exists($select, $list)) { $list = explode(',', $list);
$return = $list[$select]; }
}
if (array_key_exists($select, $list)) {
$return = $list[$select];
} }
return $return; return $return;
} }