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);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0n27Y
function name:  (null)
number of ops:  11
compiled vars:  !0 = $data, !1 = $jsonData
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   63     0  E >   ASSIGN                                                   !0, '%5B%7B%0A%09%22ObjectId%22%3A+43%2C%0A%09%22ObjectName%22%3A+%22MEGA+MELA%22%2C%0A%09%22ObjectTitle%22%3A+%22Event+Created+by+API%22%2C%0A%09%22ObjectDescription%22%3A+%22NEW+EVENT+BY+API%22%2C%0A%09%22ObjectLabel%22%3A+%22%22%2C%0A%09%22ObjectTypeId%22%3A+33%2C%0A%09%22MaxFieldsExpected%22%3A+5%2C%0A%09%22ObjectValueType%22%3A+null%2C%0A%09%22ObjectControlType%22%3A+%22%22%2C%0A%09%22IsDeleted%22%3A+true%2C%0A%09%22CreatedDate%22%3A+%222019-05-22T07%3A56%3A03.767%22%2C%0A%09%22CreatedBy%22%3A+null%2C%0A%09%22EditedDate%22%3A+null%2C%0A%09%22EditedBy%22%3A+null%2C%0A%09%22DeletedDate%22%3A+null%0A%7D%2C+%7B%0A%09%22ObjectId%22%3A+44%2C%0A%09%22ObjectName%22%3A+%22Event+x11%22%2C%0A%09%22ObjectTitle%22%3A+%22Event+Created+by+API%22%2C%0A%09%22ObjectDescription%22%3A+%22NEW+EVENT+BY+API%22%2C%0A%09%22ObjectLabel%22%3A+%22%22%2C%0A%09%22ObjectTypeId%22%3A+33%2C%0A%09%22MaxFieldsExpected%22%3A+5%2C%0A%09%22ObjectValueType%22%3A+null%2C%0A%09%22ObjectControlType%22%3A+%22%22%2C%0A%09%22IsDeleted%22%3A+true%2C%0A%09%22CreatedDate%22%3A+%222019-05-23T00%3A33%3A50.7%22%2C%0A%09%22CreatedBy%22%3A+null%2C%0A%09%22EditedDate%22%3A+null%2C%0A%09%22EditedBy%22%3A+null%2C%0A%09%22DeletedDate%22%3A+null%0A%7D%5D'
   97     1        INIT_FCALL                                               'json_decode'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 <true>
          4        DO_ICALL                                         $3      
          5        ASSIGN                                                   !1, $3
   99     6        INIT_FCALL                                               'array2table'
          7        SEND_VAR                                                 !1
          8        DO_FCALL                                      0  $5      
          9        ECHO                                                     $5
         10      > RETURN                                                   1

Function array2table:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 10
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
2 jumps found. (Code = 47) Position 1 = 13, Position 2 = 17
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 20
Branch analysis from position: 18
2 jumps found. (Code = 77) Position 1 = 27, Position 2 = 32
Branch analysis from position: 27
2 jumps found. (Code = 78) Position 1 = 28, Position 2 = 32
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
Branch analysis from position: 32
2 jumps found. (Code = 77) Position 1 = 35, Position 2 = 78
Branch analysis from position: 35
2 jumps found. (Code = 78) Position 1 = 36, Position 2 = 78
Branch analysis from position: 36
2 jumps found. (Code = 77) Position 1 = 38, Position 2 = 75
Branch analysis from position: 38
2 jumps found. (Code = 78) Position 1 = 39, Position 2 = 75
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 44
Branch analysis from position: 42
2 jumps found. (Code = 46) Position 1 = 46, Position 2 = 48
Branch analysis from position: 46
2 jumps found. (Code = 46) Position 1 = 49, Position 2 = 52
Branch analysis from position: 49
2 jumps found. (Code = 43) Position 1 = 53, Position 2 = 62
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 73
Branch analysis from position: 73
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
Branch analysis from position: 62
2 jumps found. (Code = 43) Position 1 = 65, Position 2 = 71
Branch analysis from position: 65
1 jumps found. (Code = 42) Position 1 = 72
Branch analysis from position: 72
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
Branch analysis from position: 71
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
Branch analysis from position: 52
Branch analysis from position: 48
Branch analysis from position: 44
Branch analysis from position: 75
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
Branch analysis from position: 75
Branch analysis from position: 78
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 78
Branch analysis from position: 32
Branch analysis from position: 20
Branch analysis from position: 17
Branch analysis from position: 8
filename:       /in/0n27Y
function name:  array2table
number of ops:  82
compiled vars:  !0 = $array, !1 = $recursive, !2 = $null, !3 = $table, !4 = $heading, !5 = $row, !6 = $cell
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <false>
          2        RECV_INIT                                        !2      '%26nbsp%3B'
   16     3        ISSET_ISEMPTY_CV                                 ~7      !0
          4      > JMPNZ_EX                                         ~7      ~7, ->8
          5    >   TYPE_CHECK                                  128  ~8      !0
          6        BOOL_NOT                                         ~9      ~8
          7        BOOL                                             ~7      ~9
          8    > > JMPZ                                                     ~7, ->10
   17     9    > > RETURN                                                   <false>
   20    10    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~10     !0, 0
         11        BOOL_NOT                                         ~11     ~10
         12      > JMPNZ_EX                                         ~11     ~11, ->17
         13    >   FETCH_DIM_R                                      ~12     !0, 0
         14        TYPE_CHECK                                  128  ~13     ~12
         15        BOOL_NOT                                         ~14     ~13
         16        BOOL                                             ~11     ~14
         17    > > JMPZ                                                     ~11, ->20
   21    18    >   INIT_ARRAY                                       ~15     !0
         19        ASSIGN                                                   !0, ~15
   25    20    >   ASSIGN                                                   !3, '%3Ctable%3E%0A'
   28    21        ASSIGN_OP                                     8          !3, '%09%3Ctr%3E'
   30    22        INIT_FCALL                                               'array_keys'
         23        FETCH_DIM_R                                      ~19     !0, 0
         24        SEND_VAL                                                 ~19
         25        DO_ICALL                                         $20     
         26      > FE_RESET_R                                       $21     $20, ->32
         27    > > FE_FETCH_R                                               $21, !4, ->32
   31    28    >   CONCAT                                           ~22     '%3Cth%3E', !4
         29        CONCAT                                           ~23     ~22, '%3C%2Fth%3E'
         30        ASSIGN_OP                                     8          !3, ~23
   30    31      > JMP                                                      ->27
         32    >   FE_FREE                                                  $21
   33    33        ASSIGN_OP                                     8          !3, '%3C%2Ftr%3E%0A'
   36    34      > FE_RESET_R                                       $26     !0, ->78
         35    > > FE_FETCH_R                                               $26, !5, ->78
   37    36    >   ASSIGN_OP                                     8          !3, '%09%3Ctr%3E'
   38    37      > FE_RESET_R                                       $28     !5, ->75
         38    > > FE_FETCH_R                                               $28, !6, ->75
   39    39    >   ASSIGN_OP                                     8          !3, '%3Ctd%3E'
   42    40        TYPE_CHECK                                  256          !6
         41      > JMPZ                                                     ~30, ->44
         42    >   CAST                                          7  ~31     !6
         43        ASSIGN                                                   !6, ~31
   44    44    >   TYPE_CHECK                                    8  ~33     !1
         45      > JMPZ_EX                                          ~33     ~33, ->48
         46    >   TYPE_CHECK                                  128  ~34     !6
         47        BOOL                                             ~33     ~34
         48    > > JMPZ_EX                                          ~33     ~33, ->52
         49    >   ISSET_ISEMPTY_CV                                 ~35     !6
         50        BOOL_NOT                                         ~36     ~35
         51        BOOL                                             ~33     ~36
         52    > > JMPZ                                                     ~33, ->62
   46    53    >   INIT_FCALL_BY_NAME                                       'array2table'
         54        SEND_VAR_EX                                              !6
         55        SEND_VAL_EX                                              <true>
         56        SEND_VAL_EX                                              <true>
         57        DO_FCALL                                      0  $37     
         58        CONCAT                                           ~38     '%0A', $37
         59        CONCAT                                           ~39     ~38, '%0A'
         60        ASSIGN_OP                                     8          !3, ~39
   44    61      > JMP                                                      ->73
   48    62    >   STRLEN                                           ~41     !6
         63        IS_SMALLER                                               0, ~41
         64      > JMPZ                                                     ~42, ->71
   49    65    >   INIT_FCALL                                               'htmlspecialchars'
         66        CAST                                          6  ~43     !6
         67        SEND_VAL                                                 ~43
         68        DO_ICALL                                         $44     
         69        QM_ASSIGN                                        ~45     $44
         70      > JMP                                                      ->72
   50    71    >   QM_ASSIGN                                        ~45     !2
         72    >   ASSIGN_OP                                     8          !3, ~45
   53    73    >   ASSIGN_OP                                     8          !3, '%3C%2Ftd%3E'
   38    74      > JMP                                                      ->38
         75    >   FE_FREE                                                  $28
   56    76        ASSIGN_OP                                     8          !3, '%3C%2Ftr%3E%0A'
   36    77      > JMP                                                      ->35
         78    >   FE_FREE                                                  $26
   59    79        ASSIGN_OP                                     8          !3, '%3C%2Ftable%3E'
   60    80      > RETURN                                                   !3
   61    81*     > RETURN                                                   null

End of function array2table

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.61 ms | 1017 KiB | 17 Q