Jarves\Tools::setArrayPath PHP Метод

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

(['a' => ['b' => 5]], 'a.b', 6) = ['a' => ['b' => 6]]
public static setArrayPath ( &$array, string $dotPath, mixed $value ) : mixed
$dotPath string
$value mixed
Результат mixed
    public static function setArrayPath(&$array, $dotPath, $value)
    {
        $path = explode('.', $dotPath);
        foreach ($path as $p) {
            if (!isset($array[$p])) {
                $array[$p] = [];
            }
            $array =& $array[$p];
        }
        $array = $value;
    }

Usage Example

Пример #1
0
 public function mapValues(array &$data)
 {
     Tools::setArrayPath($data, $this->getFieldDefinition()->getId(), $this->getValue());
 }