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\\\"]/')) { $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/0dEab
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 = 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 = 43) Position 1 = 9, Position 2 = 10
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 21
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 21
Branch analysis from position: 10
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/0dEab
function name:  array2CSV
number of ops:  31
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, ->24
          3    > > FE_FETCH_R                                               $5, !2, ->24
    6     4    >   ASSIGN                                                   !3, <false>
    7     5        INIT_FCALL                                               'preg_match'
          6        SEND_VAL                                                 '%2F%5B+%5Cn%5Cr%5C%5C%22%5D%2F'
          7        DO_ICALL                                         $7      
          8      > JMPZ                                                     $7, ->10
    8     9    >   ASSIGN                                                   !3, <true>
   10    10    >   INIT_FCALL                                               'str_replace'
         11        SEND_VAL                                                 <array>
         12        SEND_VAL                                                 <array>
         13        SEND_VAR                                                 !2
         14        DO_ICALL                                         $9      
         15        ASSIGN                                                   !2, $9
   11    16      > JMPZ                                                     !3, ->21
   12    17    >   ROPE_INIT                                     3  ~12     '%22'
         18        ROPE_ADD                                      1  ~12     ~12, !2
         19        ROPE_END                                      2  ~11     ~12, '%22'
         20        ASSIGN                                                   !2, ~11
   14    21    >   ASSIGN_DIM                                               !1
         22        OP_DATA                                                  !2
    5    23      > JMP                                                      ->3
         24    >   FE_FREE                                                  $5
   16    25        INIT_FCALL                                               'implode'
         26        SEND_VAL                                                 '%2C'
         27        SEND_VAR                                                 !1
         28        DO_ICALL                                         $16     
         29      > RETURN                                                   $16
   17    30*     > RETURN                                                   null

End of function array2csv

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.76 ms | 1403 KiB | 20 Q