0

My php code is here:

    $ora_result = ora_submit_query($ora_conn, $sql);

if ($ora_result) {
      while ($row = oci_fetch_array($ora_result, OCI_BOTH)) {
      print_r($row[0]." ".$row[1]." ".$row[2]."\n");
  }

And I got a result like this

=============================
2018-06-09 item1 73.8
2018-06-09 item2 83.2
2018-06-09 item3 83.2
2018-06-10 item4 33.1
2018-06-10 item5 80.2
2018-06-10 item6 77.2

I wonder if it could reform an array into

2018-06-09 73.8 83.2 83.2 
2018-06-10 33.1 80.2 77.2

and "item" consider as neglectable. The best way would be array push $row[2] value somewhere else / do a hash on key "2018-06-09"?

1 Answers1

0

I would suggest creating an array using the date as the key and pushing the values into the array list. This would look like so:

$output = array();
while($row = oci_fetch_array($ora_result, OCI_BOTH)) {
    if(!is_array($output[$row[0]]) $output[$row[0]] = array();
    array_push($output[$row[0]], $row[2]);
}

if(!empty($output)) foreach($output as $date => $number_list) {
    echo $date." ".implode(" ", $number_list);
}
Bing
  • 3,071
  • 6
  • 42
  • 81