/** * Returns the form as an array of input names and values. * * @return array */ public function as_array() { $this->as_array_data = array(); // This will dig through the Formation classes and return the values $this->process_inputs(array_merge($this->hidden, $this->inputs)); foreach (array_keys($this->as_array_data) as $key) { if (preg_match_all("#\\[([^\\]]+)\\]#", $key, $matches)) { $original_key = $key; $keys = $matches[1]; array_unshift($keys, trim(substr($key, 0, strpos($key, "[")))); $this->as_array_data = arr::set_key_path($this->as_array_data, $keys, $this->as_array_data[$original_key]); unset($this->as_array_data[$original_key]); } } return $this->as_array_data; }
/** * Sets the key path of an array to the specified value * * @param mixed pass in an key path, keys separated by decimals, or an array of keys. * @return array array with the key path set */ public static function set_key_path($arr, $path, $value) { if (!is_array($path)) { $path = explode(".", $path); } if (count($path) == 1) { $arr[$path[0]] = $value; } else { $key = array_shift($path); $arr[$key] = arr::set_key_path($arr[$key], $path, $value); } return $arr; }