diff --git a/framework/helper.class.php b/framework/helper.class.php index 861bbad31e..f3baa78ff8 100644 --- a/framework/helper.class.php +++ b/framework/helper.class.php @@ -499,6 +499,27 @@ function a($var) echo ""; } +/** + * When the $var has the $key, return it, esle result one default value. + * + * @param array|object $var + * @param string|int $key + * @param mixed $valueWhenNone value when the key not exits. + * @param mixed $valueWhenExists value when the key exits. + * @access public + * @return void + */ +function zset($var, $key, $valueWhenNone = '', $valueWhenExists = '') +{ + $var = (array)$var; + if(isset($var[$key])) + { + if($valueWhenExists) return $valueWhenExists; + return $var[$key]; + } + return $valueWhenNone; +} + /** * Judge the server ip is local or not. *