Example #1
0
 public function zip($array = null)
 {
     $arrays = self::_wrapArgs(func_get_args());
     $num_arrays = count($arrays);
     if ($num_arrays === 1) {
         return self::_wrap($array);
     }
     $__ = new self();
     $num_return_arrays = $__->max($__->map($arrays, function ($array) {
         return count($array);
     }));
     $return_arrays = $__->range($num_return_arrays);
     foreach ($return_arrays as $k => $v) {
         if (!is_array($return_arrays[$k])) {
             $return_arrays[$k] = array();
         }
         foreach ($arrays as $a => $array) {
             $return_arrays[$k][$a] = array_key_exists($k, $array) ? $array[$k] : null;
         }
     }
     return self::_wrap($return_arrays);
 }
 /**
  * Replaces the values of the array with values having the same keys in 
  * each of the following arrays. If a key from the first array exists in 
  * the second array, its value will be replaced by the value from the 
  * second array. If a key only exists in the first array, it will be left 
  * as is. If several arrays are passed for replacement, they will be 
  * processed in order, the later arrays overwriting the previous values. 
  * 
  * @param mixed $input The array from which elements will be extracted. 
  * @return ArrayObject Returns an array on success.
  * @throws RuntimeException An error occurred.
  */
 public function replace($input)
 {
     set_error_handler([$this, 'errorHandler']);
     $xargs = new self(func_get_args());
     $arg_list = $xargs->map(function ($arg) {
         return $this->xkintersect($arg)->getArrayCopy();
     })->filter('count')->unshift($this->getArrayCopy())->getArrayCopy();
     $array = call_user_func_array('array_replace', $arg_list);
     restore_error_handler();
     return $this->create($array);
 }