How to transform this php associative array? -


i have php associative input array.

array(     (int) 0 => array(         'data' => array(             'id' => '12',             'type_id' => '1',             'data_value' => '35.5000'         ),         'type' => array(             'id' => '1',             'name' => 'temperature'         )     ),     (int) 1 => array(         'data' => array(             'id' => '11',             'type_id' => '1',             'data_value' => '33.7000'         ),         'type' => array(             'id' => '1',             'name' => 'temperature'         )     ) 

i want convert output array;

array(     (int) 0 => array(         (int) 0 => array(             'v' => (int) 1         ),         (int) 1 => array(             'v' => '35.5000'         )     ),     (int) 1 => array(         (int) 0 => array(             'v' => (int) 2         ),         (int) 1 => array(             'v' => '33.7000'         )     ) 

the element data_value extracted input array output array.

the code have written looks this;

                $data2 = array();                 foreach ($inputarray $key=>$value)                 {                     $data2[] = array(                                 array(                                                                             array('v' => $key),                                     array('v' => $value['data']['data_value'])                              )                         );                 }   

unfortunately, code not work. output code looks this;

array(     (int) 0 => array(         (int) 0 => array(             (int) 0 => array(                 [maximum depth reached]             ),             (int) 1 => array(                 [maximum depth reached]             )         )     ),     (int) 1 => array(         (int) 0 => array(             (int) 0 => array(                 [maximum depth reached]             ),             (int) 1 => array(                 [maximum depth reached]             )         )     ) 

what did wrong? why error "maximum depth reached"? how can retrieve desired output array? doing in cakephp.

thank help.

that 1 wrapping array() many:

        $data2 = array();         foreach ($inputarray $key=>$value)         {             $data2[] = array(                                                                   array('v' => $key),                             array('v' => $value['data']['data_value'])                   );         }  

you can see working here. use prepare code in services ideome or plnkr in order make easier people debugging.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -