Adding same element to every level of array php -


i need add another element each level of array (sorry, think bad terminology).

i have array -

array ( [0] => array (        [actor_rt_id] => 162683283,       [item_number] => 3 )           [1] => array (        [actor_rt_id] => 162657351,        [item_number] => 5 )  ) 

this code produces array. commented out line tried add array. code before comment creates array.

$data_itemone['actor_rt_id'] = $this->input->post('actor_id'); $data_itemtwo['item_number'] = $this->input->post('item_number'); $data_item = array_merge($data_itemone, $data_itemtwo); $res = [];     foreach($data_item $key => $value){         foreach ($value $data => $thevalue) {             $res[$data][$key] = $thevalue;             //$res['film_id'] = $film_id;         }     } 

i have variable need add post single string.

 $film_id = $this->input->post('film_id'); 

i need in array -

array ( [0] => array (            [actor_rt_id] => 162683283,           [item_number] => 3,           [film_id]    => 52352           )               [1] => array (            [actor_rt_id] => 162657351,           [item_number] => 5,           [film_id]    => 52352           )  ) 

...but code (uncommented) produces -

array ( [0] => array (          [actor_rt_id] => 162683283,         [item_number] => 3        )         [film_id] => 16639,         [1] => array                  ( [actor_rt_id] => 162657351,                   [item_number] => 5 )  ) 

tried few things. can't seem work.

change

$res['film_id'] = $film_id;

to

$res[$data]['film_id'] = $film_id;

this add right array.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -