Вышел из положения следующим расширением ArrayHelper
Код: Выделить всё
class ArrayHelper extends \yii\helpers\ArrayHelper
{
/**
* Добавляет в массив значение $value в соответствии с иерархией ключей
* $indexes
* @param array $array
* @param array|string $indexes
* @param mixed $value
* @return array
*/
public static function append($array, $indexes, $value = [])
{
if ( !is_array($array)) {
return $array; }
if ( !is_array($indexes) ) {
$indexes = explode('.', $indexes); }
$idx = array_values($indexes)[0];
if ( count($indexes) > 1) {
$array[$idx] = isset($array[$idx]) ? $array[$idx] : [];
$array[$idx] = self::append($array[$idx], array_slice($indexes, 1), $value);
} elseif ( !isset($array[$idx]) ) {
$array[$idx] = $value;
}
return $array;
}
}
Код: Выделить всё
$arr = [
0 => [
'idx' => 2,
'pdx' => 3
],
1 => [
'idx' => 10
]
];
$arr1 = ArrayHelper::append($arr, [1, 'pdx'], 11);
$arr2 = ArrayHelper::append($arr, '1.pdx', 11);
/*
Массивы $arr1 и $arr2 - идентичны.
[
0 => [
'idx' => 2,
'pdx' => 3
],
1 => [
'idx' => 10,
'pdx' => 11
]
];
*/