3v4l.org

run code in 300+ PHP versions simultaneously
<?php function array2CSV(array $array) { $sanitized = array(); foreach ($array as $col) { $quote = false; if (preg_match('/[ \n\r\\\"]/', $col)) { $quote = true; } $col = str_replace(array('\\', '"', "\n", "\r"), array('\/', '\"', '\n', '\r'), $col); if ($quote) { $col = "\"$col\""; } $sanitized[] = $col; } return implode(',', $sanitized); } echo array2CSV(array('test', 'te"t\est'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Lt7OC
function name:  (null)
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   INIT_FCALL                                               'array2csv'
          1        SEND_VAL                                                 <array>
          2        DO_FCALL                                      0  $0      
          3        ECHO                                                     $0
          4      > RETURN                                                   1

Function array2csv:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 25
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 25
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 11
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 22
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 22
Branch analysis from position: 11
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/Lt7OC
function name:  array2CSV
number of ops:  32
compiled vars:  !0 = $array, !1 = $sanitized, !2 = $col, !3 = $quote
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        ASSIGN                                                   !1, <array>
    5     2      > FE_RESET_R                                       $5      !0, ->25
          3    > > FE_FETCH_R                                               $5, !2, ->25
    6     4    >   ASSIGN                                                   !3, <false>
    7     5        INIT_FCALL                                               'preg_match'
          6        SEND_VAL                                                 '%2F%5B+%5Cn%5Cr%5C%5C%22%5D%2F'
          7        SEND_VAR                                                 !2
          8        DO_ICALL                                         $7      
          9      > JMPZ                                                     $7, ->11
    8    10    >   ASSIGN                                                   !3, <true>
   10    11    >   INIT_FCALL                                               'str_replace'
         12        SEND_VAL                                                 <array>
         13        SEND_VAL                                                 <array>
         14        SEND_VAR                                                 !2
         15        DO_ICALL                                         $9      
         16        ASSIGN                                                   !2, $9
   11    17      > JMPZ                                                     !3, ->22
   12    18    >   ROPE_INIT                                     3  ~12     '%22'
         19        ROPE_ADD                                      1  ~12     ~12, !2
         20        ROPE_END                                      2  ~11     ~12, '%22'
         21        ASSIGN                                                   !2, ~11
   14    22    >   ASSIGN_DIM                                               !1
         23        OP_DATA                                                  !2
    5    24      > JMP                                                      ->3
         25    >   FE_FREE                                                  $5
   16    26        INIT_FCALL                                               'implode'
         27        SEND_VAL                                                 '%2C'
         28        SEND_VAR                                                 !1
         29        DO_ICALL                                         $16     
         30      > RETURN                                                   $16
   17    31*     > RETURN                                                   null

End of function array2csv

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.17 ms | 948 KiB | 21 Q