Sets a value in a multi-dimensional array.


Syntax

array_set(array $array, array $members, $value): array


Parameter

@param array $array A multi-dimensional numeric or associative array. If no array is given, an empty one is created automatically.

@param array| $members A path of property to set. Either a numerical array containing the member path or a string with dot-notation.

@param $value The value you want to set.


Return

Returns the complete modified array.


Examples

Writing in your twig source code:

Path, as array:

{% set myArr = hublify.array_set(myArr, ['a','sub','path'], 'Aloha!') %}

gives you (hublify.dump'ed):

myArr = [
  [a] => [
    [sub] => [
      [path] => "Aloha!"
    ]
  ]
]


Path, as dot-notated string:

{% set myArr = hublify.array_set(myArr, 'a.sub.path', 'Aloha!') %}

gives you (hublify.dump'ed):

myArr = [
  [a] => [
    [sub] => [
      [path] => "Aloha!"
    ]
  ]
]