3v4l.org

run code in 300+ PHP versions simultaneously
<?php function fillSheet($sheet, $fields, $data) { // headers $colLetter = "A"; $rowNumber = 1; // A1...Z1 for header foreach ($fields as $fieldname){ $sheet->setCellValue($colLetter.$rowNumber, $fieldname); $colLetter++; } // A2..Z999 for the rest foreach ($data as $row) { $rowNumber++; $colLetter = "A"; foreach ($fields as $i => $fieldname) { $sheet->setCellValue($colLetter.$rowNumber, $row[$i]); $colLetter++; } } } // mock class Sheet { public function setCellValue($a, $b) { echo "$a : $b\n"; } }; $sheet = new Sheet(); $ids = ["1", "2", "3"]; $fields = ["firstname", "lastname", "phonenumber"]; $data = [ ['Mary', 'Stuart', '555-555-0001'], ['John', 'Doe', '555-555-5555'] ]; // end mock /* $ids = $_POST["id"]; $values = $_POST["values"]; $sqlIds = implode(",", $ids); $sqlFields = implode(",", $fields); $sql="SELECT $sqlFields FROM database WHERE id IN ($sqlIds)"; $result = mysqli_query($connect, $sql); $data = []; while ($row = mysqli_fetch_array($result)) { $data[] = $row; } */ fillSheet($sheet, $fields, $data);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lZVXm
function name:  (null)
number of ops:  12
compiled vars:  !0 = $sheet, !1 = $ids, !2 = $fields, !3 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   NEW                                              $4      'Sheet'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $4
   28     3        ASSIGN                                                   !1, <array>
   29     4        ASSIGN                                                   !2, <array>
   31     5        ASSIGN                                                   !3, <array>
   52     6        INIT_FCALL                                               'fillsheet'
          7        SEND_VAR                                                 !0
          8        SEND_VAR                                                 !2
          9        SEND_VAR                                                 !3
         10        DO_FCALL                                      0          
         11      > RETURN                                                   1

Function fillsheet:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 14
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 14
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 14
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 33
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 33
Branch analysis from position: 17
2 jumps found. (Code = 77) Position 1 = 20, Position 2 = 31
Branch analysis from position: 20
2 jumps found. (Code = 78) Position 1 = 21, Position 2 = 31
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 31
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
Branch analysis from position: 14
filename:       /in/lZVXm
function name:  fillSheet
number of ops:  35
compiled vars:  !0 = $sheet, !1 = $fields, !2 = $data, !3 = $colLetter, !4 = $rowNumber, !5 = $fieldname, !6 = $row, !7 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
    4     3        ASSIGN                                                   !3, 'A'
    5     4        ASSIGN                                                   !4, 1
    8     5      > FE_RESET_R                                       $10     !1, ->14
          6    > > FE_FETCH_R                                               $10, !5, ->14
    9     7    >   INIT_METHOD_CALL                                         !0, 'setCellValue'
          8        CONCAT                                           ~11     !3, !4
          9        SEND_VAL_EX                                              ~11
         10        SEND_VAR_EX                                              !5
         11        DO_FCALL                                      0          
   10    12        PRE_INC                                                  !3
    8    13      > JMP                                                      ->6
         14    >   FE_FREE                                                  $10
   14    15      > FE_RESET_R                                       $14     !2, ->33
         16    > > FE_FETCH_R                                               $14, !6, ->33
   15    17    >   PRE_INC                                                  !4
   16    18        ASSIGN                                                   !3, 'A'
   17    19      > FE_RESET_R                                       $17     !1, ->31
         20    > > FE_FETCH_R                                       ~18     $17, !5, ->31
         21    >   ASSIGN                                                   !7, ~18
   18    22        INIT_METHOD_CALL                                         !0, 'setCellValue'
         23        CONCAT                                           ~20     !3, !4
         24        SEND_VAL_EX                                              ~20
         25        CHECK_FUNC_ARG                                           
         26        FETCH_DIM_FUNC_ARG                               $21     !6, !7
         27        SEND_FUNC_ARG                                            $21
         28        DO_FCALL                                      0          
   19    29        PRE_INC                                                  !3
   17    30      > JMP                                                      ->20
         31    >   FE_FREE                                                  $17
   14    32      > JMP                                                      ->16
         33    >   FE_FREE                                                  $14
   22    34      > RETURN                                                   null

End of function fillsheet

Class Sheet:
Function setcellvalue:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lZVXm
function name:  setCellValue
number of ops:  8
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        ROPE_INIT                                     4  ~3      !0
          3        ROPE_ADD                                      1  ~3      ~3, '+%3A+'
          4        ROPE_ADD                                      2  ~3      ~3, !1
          5        ROPE_END                                      3  ~2      ~3, '%0A'
          6        ECHO                                                     ~2
          7      > RETURN                                                   null

End of function setcellvalue

End of class Sheet.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.75 ms | 1403 KiB | 14 Q