3v4l.org

run code in 300+ PHP versions simultaneously
<?php function toArray($s){ $operators = array('+','-','*','/','%','(',')'); $finalArr = []; $curStr = ''; foreach (str_split($s) as $char) { if (in_array($char, $operators)) { //Alright, we have an operator. Append the entire number $finalArr[] = $curStr; //And also the operator $finalArr[] = $char; //Reset the current string back to empty $curStr = ''; } else { //Not an operator? Just keep appending the current number $curStr .= $char; } } //Add final leftover string if ($curStr !== '') { //Sanity check here (This shouldn't ever be empty, as you wouldn't end with an operator) $finalArr[] = $curStr; } //Return return $finalArr; } $string = '6+4*4+100+444*6*13*14'; $arr = toArray($string); print_r($arr);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mDEPu
function name:  (null)
number of ops:  9
compiled vars:  !0 = $string, !1 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   ASSIGN                                                   !0, '6%2B4%2A4%2B100%2B444%2A6%2A13%2A14'
   34     1        INIT_FCALL                                               'toarray'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $3      
          4        ASSIGN                                                   !1, $3
   36     5        INIT_FCALL                                               'print_r'
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                                 
          8      > RETURN                                                   1

Function toarray:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 22
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 22
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 20
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 27
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
Branch analysis from position: 22
filename:       /in/mDEPu
function name:  toArray
number of ops:  29
compiled vars:  !0 = $s, !1 = $operators, !2 = $finalArr, !3 = $curStr, !4 = $char
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    5     1        ASSIGN                                                   !1, <array>
    7     2        ASSIGN                                                   !2, <array>
    8     3        ASSIGN                                                   !3, ''
    9     4        INIT_FCALL                                               'str_split'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $8      
          7      > FE_RESET_R                                       $9      $8, ->22
          8    > > FE_FETCH_R                                               $9, !4, ->22
   10     9    >   INIT_FCALL                                               'in_array'
         10        SEND_VAR                                                 !4
         11        SEND_VAR                                                 !1
         12        DO_ICALL                                         $10     
         13      > JMPZ                                                     $10, ->20
   12    14    >   ASSIGN_DIM                                               !2
         15        OP_DATA                                                  !3
   14    16        ASSIGN_DIM                                               !2
         17        OP_DATA                                                  !4
   16    18        ASSIGN                                                   !3, ''
   10    19      > JMP                                                      ->21
   19    20    >   ASSIGN_OP                                     8          !3, !4
    9    21    > > JMP                                                      ->8
         22    >   FE_FREE                                                  $9
   24    23        IS_NOT_IDENTICAL                                         !3, ''
         24      > JMPZ                                                     ~15, ->27
   25    25    >   ASSIGN_DIM                                               !2
         26        OP_DATA                                                  !3
   29    27    > > RETURN                                                   !2
   30    28*     > RETURN                                                   null

End of function toarray

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.23 ms | 1020 KiB | 17 Q