Pommo_Helper::arrayIntersect PHP Method

arrayIntersect() static public method

returns an array containing all the values of array1 which have matching keys that are present in a2
static public arrayIntersect ( &$a1, &$a2 )
    static function &arrayIntersect(&$a1, &$a2)
    {
        $o = array();
        if (!is_array($a1) || !is_array($a2)) {
            return $o;
        }
        foreach (array_keys($a2) as $key) {
            if (isset($a1[$key])) {
                $o[$key] = $a1[$key];
            }
        }
        return $o;
    }

Usage Example

示例#1
0
 static function &stateInit($name = 'default', $defaults = array(), $source = array())
 {
     if (empty(Pommo::$_session['state'][$name])) {
         Pommo::$_session['state'][$name] =& $defaults;
     }
     $state =& Pommo::$_session['state'][$name];
     if (empty($defaults)) {
         return $state;
     }
     //Add support for passing multi select options
     if (is_array($source)) {
         foreach ($source as $k => $v) {
             if (is_array($source[$k])) {
                 $source[$k] = implode(',', $source[$k]);
             }
         }
     }
     foreach (array_keys($state) as $key) {
         if (array_key_exists($key, $source)) {
             $state[$key] = $source[$key];
         }
     }
     // normalize the page state
     if (count($state) > count($defaults)) {
         $state = Pommo_Helper::arrayIntersect($state, $defaults);
     }
     return $state;
 }
All Usage Examples Of Pommo_Helper::arrayIntersect