FluidTYPO3\Flux\Utility\RecursiveArrayUtility::convertPathToArray PHP Метод

convertPathToArray() публичный статический Метод

This method convert a string like "Some.long.tree" into an array ["Some"=>["long"=>["tree"=> $value]]]
public static convertPathToArray ( string $path, mixed $value = NULL ) : array
$path string
$value mixed
Результат array
    public static function convertPathToArray($path, $value = NULL)
    {
        $array = array();
        if (strpos($path, '.') === FALSE) {
            $array[$path] = $value;
        } else {
            $target =& $array;
            foreach (explode('.', $path) as $segment) {
                if (!array_key_exists($segment, $target) || !is_array($target[$segment])) {
                    $target[$segment] = array();
                }
                $target =& $target[$segment];
            }
            $target = $value;
        }
        return $array;
    }

Usage Example

Пример #1
0
 /**
  * @param string $name
  * @param mixed $value
  * @return FormInterface
  */
 public function setVariable($name, $value)
 {
     $this->variables = RecursiveArrayUtility::mergeRecursiveOverrule($this->variables, RecursiveArrayUtility::convertPathToArray($name, $value));
     return $this;
 }