/** * Recursive version of PHPs array_map * * @param mixed $callback * @param array $arr * @return array */ function zula_array_map_recursive($callback, array $arr) { foreach ($arr as $key => $val) { if (is_array($val)) { $arr[$key] = zula_array_map_recursive($callback, $val); } else { $arr[$key] = call_user_func($callback, $val); } } return $arr; }
/** * Returns the value of the correct input type. To access a * multidimensional array, use the syntax 'foo/bar/car' where * a '/' deliminates the next array index. * * @param string $key * @param string $type * @param bool $trim * @return mixed */ public function get($key, $type = 'get', $trim = true) { $type = strtoupper($type); if ($this->inputs[$type] === null) { $this->fetchInput($type); } $key = preg_split('#(?<!\\\\)/#', trim($key, '/')); foreach ($key as $val) { $val = stripslashes($val); if (!isset($tmpVal) && isset($this->inputs[$type][$val])) { $tmpVal = $this->inputs[$type][$val]; } else { if (isset($tmpVal) && is_array($tmpVal) && isset($tmpVal[$val])) { $tmpVal = $tmpVal[$val]; } else { throw new Input_KeyNoExist('input key "' . stripslashes(implode('/', $key)) . '" for data type "' . $type . '" does not exist'); } } } if ($trim) { $tmpVal = is_array($tmpVal) ? zula_array_map_recursive('trim', $tmpVal) : trim($tmpVal); } return $tmpVal; }