/** |
* Element |
* |
* 取数组中的元素,判断键名是否存在并且判断值是否存在 |
* |
*/ |
if ( ! function_exists( 'element' )) |
{ |
function element( $item , $array , $default = FALSE) |
{ |
if ( ! isset( $array [ $item ]) OR $array [ $item ] == "" ) |
{ |
return $default ; |
} |
return $array [ $item ]; |
} |
} |
// ------------------------------------------------------------------------ |
/** |
* 随机返回数组内的一个函数,用array_rand()获取随机键名 |
* |
* @access public |
* @param array |
* @return mixed depends on what the array contains |
*/ |
if ( ! function_exists( 'random_element' )) |
{ |
function random_element( $array ) |
{ |
if ( ! is_array ( $array )) |
{ |
return $array ; |
} |
return $array [ array_rand ( $array )]; |
} |
} |
// -------------------------------------------------------------------- |
/** |
* Elements |
* |
* 从数组中返回若干单元,若数组不存在则返回false |
* |
* @access public |
* @param array |
* @param array |
* @param mixed |
* @return mixed depends on what the array contains |
*/ |
if ( ! function_exists( 'elements' )) |
{ |
function elements( $items , $array , $default = FALSE) |
{ |
$return = array (); |
if ( ! is_array ( $items )) |
{ |
$items = array ( $items ); |
} |
foreach ( $items as $item ) |
{ |
if (isset( $array [ $item ])) |
{ |
$return [ $item ] = $array [ $item ]; |
} |
else |
{ |
$return [ $item ] = $default ; |
} |
} |
return $return ; |
} |
} |