Create Array From Current Array using PHP -


this result of array after build using array_push function mssql result.

array (     [0] => array         (             [sticker] => falcon             [month] => 1             [jum] => 65826210.00         )      [1] => array         (             [sticker] => falcon             [month] => 2             [jum] => 68070573.00         )      [2] => array         (             [sticker] => falcon             [month] => 3             [jum] => 99053067.60         )      [3] =>      [4] => array         (             [sticker] => hrd             [month] => 2             [jum] => 1521400.00         )      [5] => array         (             [sticker] => hrd             [month] => 3             [jum] => 2093200.00         ) ) 

i need convert array above structure:

array (     [0] => array         (             [0] =>              [1] => 1             [2] => 2             [3] => 3         )     [1] => array         (             [0] => falcon             [1] => 65826210.00             [2] => 68070573.00             [3] => 99053067.60         )     [2] => array         (             [0] => hrd             [1] => 0             [2] => 1521400.00             [3] => 2093200.00         ) ) 

note: array[0] values 1,2,3 (this actualy month, input 3 in order code not long. 12 (jan - dec)).

if original array, there none value (example array[3]), convert new array[2]->[1] value 0.

any appreciated. all!.

try not issue empty array not understand how program know sticker hrd filled zero.but later check if every month "isset" , if not act zero

$arr1=array(  array('sticker'=>'falcon','month'=>1,'jum'=>65826210.00),  array('sticker'=>'falcon','month'=>2,'jum'=>68070573.00),  array('sticker'=>'falcon','month'=>3,'jum'=>99053067.60),  array(),  array('sticker'=>'hrd','month'=>2,'jum'=>1521400.00),  array('sticker'=>'hrd','month'=>3,'jum'=>2093200.00), );  $arr2=array(); $arr3=array();  $arr2[0][0]=""; foreach($arr1 $key => $val){  if(!empty($val)){     $arr2[0][$val['month']]=$val['month'];      //group each sticker     $arr3[$val['sticker']][]=$val['jum'];  } }  //transfer grouped data arr2 foreach($arr3 $key => $val){   $tmp_arr=array($key);    $arr2[]=array_merge($tmp_arr,$val); }   print_r($arr2); 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - How to Hide Date Menu from Datepicker in yii2 -