3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Translate a result array into a HTML table * * @author Aidan Lister <aidan@php.net> * @version 1.3.2 * @link http://aidanlister.com/2004/04/converting-arrays-to-human-readable-tables/ * @param array $array The result (numericaly keyed, associative inner) array. * @param bool $recursive Recursively generate tables for multi-dimensional arrays * @param string $null String to output for blank cells */ function array2table($array, $recursive = false, $null = '&nbsp;') { // Sanity check if (empty($array) || !is_array($array)) { return false; } if (!isset($array[0]) || !is_array($array[0])) { $array = array($array); } // Start the table $table = "<table>\n"; // The header $table .= "\t<tr>"; // Take the keys from the first row as the headings foreach (array_keys($array[0]) as $heading) { $table .= '<th>' . $heading . '</th>'; } $table .= "</tr>\n"; // The body foreach ($array as $row) { $table .= "\t<tr>" ; foreach ($row as $cell) { $table .= '<td>'; // Cast objects if (is_object($cell)) { $cell = (array) $cell; } if ($recursive === true && is_array($cell) && !empty($cell)) { // Recursive mode $table .= "\n" . array2table($cell, true, true) . "\n"; } else { $table .= (strlen($cell) > 0) ? htmlspecialchars((string) $cell) : $null; } $table .= '</td>'; } $table .= "</tr>\n"; } $table .= '</table>'; return $table; } $data ='[{ "ObjectId": 43, "ObjectName": "MEGA MELA", "ObjectTitle": "Event Created by API", "ObjectDescription": "NEW EVENT BY API", "ObjectLabel": "", "ObjectTypeId": 33, "MaxFieldsExpected": 5, "ObjectValueType": null, "ObjectControlType": "", "IsDeleted": true, "CreatedDate": "2019-05-22T07:56:03.767", "CreatedBy": null, "EditedDate": null, "EditedBy": null, "DeletedDate": null }, { "ObjectId": 44, "ObjectName": "Event x11", "ObjectTitle": "Event Created by API", "ObjectDescription": "NEW EVENT BY API", "ObjectLabel": "", "ObjectTypeId": 33, "MaxFieldsExpected": 5, "ObjectValueType": null, "ObjectControlType": "", "IsDeleted": true, "CreatedDate": "2019-05-23T00:33:50.7", "CreatedBy": null, "EditedDate": null, "EditedBy": null, "DeletedDate": null }]'; $jsonData = json_decode($data, TRUE); echo array2table($jsonData);
Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /in/0n27Y on line 48 Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /in/0n27Y on line 48 Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /in/0n27Y on line 48 Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /in/0n27Y on line 48 Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /in/0n27Y on line 48 Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /in/0n27Y on line 48 Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /in/0n27Y on line 48 Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /in/0n27Y on line 48 Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /in/0n27Y on line 48 Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /in/0n27Y on line 48 <table> <tr><th>ObjectId</th><th>ObjectName</th><th>ObjectTitle</th><th>ObjectDescription</th><th>ObjectLabel</th><th>ObjectTypeId</th><th>MaxFieldsExpected</th><th>ObjectValueType</th><th>ObjectControlType</th><th>IsDeleted</th><th>CreatedDate</th><th>CreatedBy</th><th>EditedDate</th><th>EditedBy</th><th>DeletedDate</th></tr> <tr><td>43</td><td>MEGA MELA</td><td>Event Created by API</td><td>NEW EVENT BY API</td><td>&nbsp;</td><td>33</td><td>5</td><td>&nbsp;</td><td>&nbsp;</td><td>1</td><td>2019-05-22T07:56:03.767</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr> <tr><td>44</td><td>Event x11</td><td>Event Created by API</td><td>NEW EVENT BY API</td><td>&nbsp;</td><td>33</td><td>5</td><td>&nbsp;</td><td>&nbsp;</td><td>1</td><td>2019-05-23T00:33:50.7</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr> </table>
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
<table> <tr><th>ObjectId</th><th>ObjectName</th><th>ObjectTitle</th><th>ObjectDescription</th><th>ObjectLabel</th><th>ObjectTypeId</th><th>MaxFieldsExpected</th><th>ObjectValueType</th><th>ObjectControlType</th><th>IsDeleted</th><th>CreatedDate</th><th>CreatedBy</th><th>EditedDate</th><th>EditedBy</th><th>DeletedDate</th></tr> <tr><td>43</td><td>MEGA MELA</td><td>Event Created by API</td><td>NEW EVENT BY API</td><td>&nbsp;</td><td>33</td><td>5</td><td>&nbsp;</td><td>&nbsp;</td><td>1</td><td>2019-05-22T07:56:03.767</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr> <tr><td>44</td><td>Event x11</td><td>Event Created by API</td><td>NEW EVENT BY API</td><td>&nbsp;</td><td>33</td><td>5</td><td>&nbsp;</td><td>&nbsp;</td><td>1</td><td>2019-05-23T00:33:50.7</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr> </table>

preferences:
158.29 ms | 412 KiB | 5 Q