3v4l.org

run code in 300+ PHP versions simultaneously
<?php $keys = array(); $header = array(); //get all keyes from first object foreach($q2 as $key){ $header[] = $key->row_name; } $q2a = json_decode(json_encode($q2), true); foreach($q2a as $q){ foreach($q as $k => $v){ $tmp_array[$k][] = $v; } } $output='<table><tr><th></th>'; foreach($header as $key){ $output .= '<th>' . $key . '</th>'; } $output .= '</tr>'; $tmp_array = array_slice($tmp_array, 1, -1); foreach($tmp_array as $key => $val){ $arl = count($val); $output .= '<tr>'; //display keys for($i = 0; $i < $arl ; $i++ ){ $output .= '<td>'. $key[$i] .'</td>'; //display values for($i = 0; $i < $arl; $i++ ){ $output .= '<td>'. $val[$i] .'</td>'; } $output .= '</tr>'; } } $output .= '</table>'; echo $output;

preferences:
24.85 ms | 406 KiB | 5 Q