Json array in php code -
i need use json array in php code. problem i'm in loop , need separate array in 2 , want merge it. far didn't work. use have graph (jqxchart).
here code
for($i = 0; $i < $nb; $i++){ if ($i%2 == 1){ $time[$i] = (hexdec($hour[$i])); $orders1[] = array( 'orderdate' => $time[$i], ); }else{ $hour[$i] = $hour[$i] + 1; $orders2[] = array( 'productname' => $hour[$i], ); } } $orders[] = array_merge_recursive( $orders1[], $orders2[] ); } echo json_encode($orders);
thanks
try code,
$orders1 = array(); $orders2 = array(); for($i = 0; $i < $nb; $i++){ if ($i%2 == 1){ .... $temp1 = array( 'orderdate' => $time[$i], ); array_push($orders1, $temp1); }else{ .... $temp2 = array( 'productname' => $hour[$i], ); array_push($orders2, $temp2); } } } $orders = array_merge( $orders1, $orders2 ); echo json_encode($orders);
Comments
Post a Comment