3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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;
based on A8khD
Output for 5.5.0 - 7.2.6
Notice: Undefined variable: q2 in /in/qvuvi on line 7 Warning: Invalid argument supplied for foreach() in /in/qvuvi on line 7 Notice: Undefined variable: q2 in /in/qvuvi on line 11 Warning: Invalid argument supplied for foreach() in /in/qvuvi on line 12 Notice: Undefined variable: tmp_array in /in/qvuvi on line 26 Warning: array_slice() expects parameter 1 to be array, null given in /in/qvuvi on line 26 Warning: Invalid argument supplied for foreach() in /in/qvuvi on line 28 <table><tr><th></th></tr></table>