diff --git a/cake/libs/object.php b/cake/libs/object.php index ad43d6539..15ef1feb6 100644 --- a/cake/libs/object.php +++ b/cake/libs/object.php @@ -75,18 +75,27 @@ class Object{ 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 array $list - * @return string the value of the array key + * @param mixed $list can be an array or a coma separated list. + * @return string the value of the array key or null if no match */ function enum($select, $list = array('no', 'yes')) { $return = null; - if(is_array($list)){ - if (array_key_exists($select, $list)) { - $return = $list[$select]; - } + if(is_string($list)) { + $list = explode(',', $list); + } + + if (array_key_exists($select, $list)) { + $return = $list[$select]; } return $return; }