From fc83f4c96300ef422704ca48a0f55e1ebc221e0a Mon Sep 17 00:00:00 2001 From: wangchunsheng Date: Thu, 10 Jan 2013 15:16:34 +0000 Subject: [PATCH] + add the function of zset(). --- framework/helper.class.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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. *