3v4l.org

run code in 300+ PHP versions simultaneously
<?php $myArray = array( array( 1, 2, 3, 4, "a" ), array( 'a', "b", 'c', "d", 3 ), array( 'this is a quote " blah blah blah', "b", 'c', "d", 3 ) ); $csvOutput = ''; foreach($myArray as $key => $row) { $rowString = ''; foreach($row as $key => $col) { $rowString .= '"' . sanitize($col) . '", '; } $csvOutput .= rtrim($rowString, ', ') . "\n"; } echo $csvOutput; function sanitize($input) { return str_replace('"', '""', $input); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 24
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 24
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 16
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 16
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 16
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/JHkqd
function name:  (null)
number of ops:  27
compiled vars:  !0 = $myArray, !1 = $csvOutput, !2 = $row, !3 = $key, !4 = $rowString, !5 = $col
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   15     1        ASSIGN                                                   !1, ''
   16     2      > FE_RESET_R                                       $8      !0, ->24
          3    > > FE_FETCH_R                                       ~9      $8, !2, ->24
          4    >   ASSIGN                                                   !3, ~9
   17     5        ASSIGN                                                   !4, ''
   18     6      > FE_RESET_R                                       $12     !2, ->16
          7    > > FE_FETCH_R                                       ~13     $12, !5, ->16
          8    >   ASSIGN                                                   !3, ~13
   19     9        INIT_FCALL_BY_NAME                                       'sanitize'
         10        SEND_VAR_EX                                              !5
         11        DO_FCALL                                      0  $15     
         12        CONCAT                                           ~16     '%22', $15
         13        CONCAT                                           ~17     ~16, '%22%2C+'
         14        ASSIGN_OP                                     8          !4, ~17
   18    15      > JMP                                                      ->7
         16    >   FE_FREE                                                  $12
   21    17        INIT_FCALL                                               'rtrim'
         18        SEND_VAR                                                 !4
         19        SEND_VAL                                                 '%2C+'
         20        DO_ICALL                                         $19     
         21        CONCAT                                           ~20     $19, '%0A'
         22        ASSIGN_OP                                     8          !1, ~20
   16    23      > JMP                                                      ->3
         24    >   FE_FREE                                                  $8
   23    25        ECHO                                                     !1
   27    26      > RETURN                                                   1

Function sanitize:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JHkqd
function name:  sanitize
number of ops:  8
compiled vars:  !0 = $input
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
   26     1        INIT_FCALL                                               'str_replace'
          2        SEND_VAL                                                 '%22'
          3        SEND_VAL                                                 '%22%22'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $1      
          6      > RETURN                                                   $1
   27     7*     > RETURN                                                   null

End of function sanitize

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
169.62 ms | 1400 KiB | 17 Q