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;
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.31, 8.2.0 - 8.2.27, 8.3.0 - 8.3.15, 8.4.1 - 8.4.2
Warning: Undefined variable $q2 in /in/qvuvi on line 7 Warning: foreach() argument must be of type array|object, null given in /in/qvuvi on line 7 Warning: Undefined variable $q2 in /in/qvuvi on line 11 Warning: foreach() argument must be of type array|object, null given in /in/qvuvi on line 12 Warning: Undefined variable $tmp_array in /in/qvuvi on line 26 Fatal error: Uncaught TypeError: array_slice(): Argument #1 ($array) must be of type array, null given in /in/qvuvi:26 Stack trace: #0 /in/qvuvi(26): array_slice(NULL, 1, -1) #1 {main} thrown in /in/qvuvi on line 26
Process exited with code 255.
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
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>
Output for 7.3.32 - 7.3.33
Warning: Invalid argument supplied for foreach() in /in/qvuvi on line 7 Warning: Invalid argument supplied for foreach() in /in/qvuvi on line 12 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>

preferences:
48.94 ms | 410 KiB | 5 Q