Как добавить массив к каждому элементу другого массива с моим выбором ключа и значения (в php)?

Этот код:

for ($p=0;$p<count($results);$p++){ foreach ($results[$p] as $k => $v){ $typeee = ['type' => strtolower(str_replace('_','',$results[$p][$k]['metric']))."container"]; array_insert2($results[$p],0,$typeee); } } print_r($results); 

дает мне это:

 Array ( [0] => Array ( [type] => pagestoriescontainer [0] => Array ( [type] => pagestories [object_id] => 123456778 [metric] => page_stories [end_time] => 1386057600 [period] => 86400 [value] => 2090 ) [1] => Array ( [type] => pagestorytellers [object_id] => 123456778 [metric] => page_storytellers [end_time] => 1386057600 [period] => 86400 [value] => 2041 ) [...] [1] => Array ( [0] => Array ( [type] => pagestories [object_id] => 199193463123456778 [metric] => page_stories [end_time] => 1386057600 [period] => 86400 [value] => 0 ) [1] => Array ( [type] => pagestorytellers [object_id] => 199193463123456778 [metric] => page_storytellers [end_time] => 1386057600 [period] => 86400 [value] => 0 ) [...] 

Но этот код:

 for ($p=0;$p<count($results);$p++){ foreach ($results[$p] as $k => $v){ $typeee = ['type' => strtolower(str_replace('_','',$results[$p][$k]['metric']))."container"]; array_insert2($results[$p],$k,$typeee); } } 

НЕ дает мне это:

 Array ( [0] => Array ( [type] => pagestoriescontainer [0] => Array ( [type] => pagestories [object_id] => 123456778 [metric] => page_stories [end_time] => 1386057600 [period] => 86400 [value] => 2090 ) [type] => pagestorytellerscontainer [1] => Array ( [type] => pagestorytellers [object_id] => 123456778 [metric] => page_storytellers [end_time] => 1386057600 [period] => 86400 [value] => 2041 ) [...] [1] => Array ( [type] => pagestoriescontainer [0] => Array ( [type] => pagestories [object_id] => 199193463123456778 [metric] => page_stories [end_time] => 1386057600 [period] => 86400 [value] => 0 ) [type] => pagestorytellerscontainer [1] => Array ( [type] => pagestorytellers [object_id] => 199193463123456778 [metric] => page_storytellers [end_time] => 1386057600 [period] => 86400 [value] => 0 ) [...] 

Зачем? Как я могу получить то, что хочу? 🙂

Также,

 function array_insert2 (&$array, $position, $insert_array) { $first_array = array_splice ($array, 0, $position); $array = array_merge ($first_array, $insert_array, $array); } 

Solutions Collecting From Web of "Как добавить массив к каждому элементу другого массива с моим выбором ключа и значения (в php)?"