Kraken\Util\Support\ArraySupport::expand PHP Method

expand() public static method

Expand flattened array into a multi-dimensional one.
public static expand ( $array ) : array
$array
return array
    public static function expand($array)
    {
        $multiArray = [];
        foreach ($array as $key => &$value) {
            $keys = explode('.', $key);
            $lastKey = array_pop($keys);
            $currentPointer =& $multiArray;
            foreach ($keys as $currentKey) {
                if (!isset($currentPointer[$currentKey])) {
                    $currentPointer[$currentKey] = [];
                }
                $currentPointer =& $currentPointer[$currentKey];
            }
            $currentPointer[$lastKey] = $value;
        }
        return $multiArray;
    }

Usage Example

コード例 #1
0
ファイル: ConfigTest.php プロジェクト: kraken-php/framework
 /**
  * @return array
  */
 public function getExpanded()
 {
     return ArraySupport::expand($this->getRaw());
 }
All Usage Examples Of Kraken\Util\Support\ArraySupport::expand