3v4l.org

run code in 300+ PHP versions simultaneously
<?php $result = [ ["Apple iPhone 13 128 Go Minuit", "1 379€00"], ["Apple iPhone 14 128 Go Minuit", "1 379€00"], ["Apple iPhone 14 128 Go Lumière Stellaire", "919€00"], ["Apple iPhone 14 Pro 128 Go Noir Sidéral", "919€00"] ]; foreach ($result as $item) { $price = $item['1']; $convert_array = ['$', '€', '£', '¥', '₩', '₹', '₽', '฿', '₺', '₴']; foreach ($convert_array as $symbol) { if (strpos($price, $symbol) !== false) { $price = str_replace($symbol, '.', $price); $price = preg_replace('/\. /', '', $price, 1); $price = str_replace(',', '.', $price); break; } } $price_format = trim($price); if (substr($price_format, -1) == '.') { $price_format = substr($price_format, 0, -1); } if (is_string($price_format)) { $price_format = number_format((float)str_replace(' ','',$price_format), 2, '.', ' '); } if (is_numeric($price_format)) { $price_format = $price_format . ' num'; } print_r($price_format); echo PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 78
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 78
Branch analysis from position: 3
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 35
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 35
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 34
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 52
Branch analysis from position: 46
2 jumps found. (Code = 43) Position 1 = 54, Position 2 = 67
Branch analysis from position: 54
2 jumps found. (Code = 43) Position 1 = 71, Position 2 = 73
Branch analysis from position: 71
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 73
Branch analysis from position: 67
Branch analysis from position: 52
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 35
Branch analysis from position: 35
Branch analysis from position: 78
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 78
filename:       /in/OCSWN
function name:  (null)
number of ops:  80
compiled vars:  !0 = $result, !1 = $item, !2 = $price, !3 = $convert_array, !4 = $symbol, !5 = $price_format
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   10     1      > FE_RESET_R                                       $7      !0, ->78
          2    > > FE_FETCH_R                                               $7, !1, ->78
   11     3    >   FETCH_DIM_R                                      ~8      !1, 1
          4        ASSIGN                                                   !2, ~8
   13     5        ASSIGN                                                   !3, <array>
   15     6      > FE_RESET_R                                       $11     !3, ->35
          7    > > FE_FETCH_R                                               $11, !4, ->35
   16     8    >   INIT_FCALL                                               'strpos'
          9        SEND_VAR                                                 !2
         10        SEND_VAR                                                 !4
         11        DO_ICALL                                         $12     
         12        TYPE_CHECK                                  1018          $12
         13      > JMPZ                                                     ~13, ->34
   17    14    >   INIT_FCALL                                               'str_replace'
         15        SEND_VAR                                                 !4
         16        SEND_VAL                                                 '.'
         17        SEND_VAR                                                 !2
         18        DO_ICALL                                         $14     
         19        ASSIGN                                                   !2, $14
   18    20        INIT_FCALL                                               'preg_replace'
         21        SEND_VAL                                                 '%2F%5C.+%2F'
         22        SEND_VAL                                                 ''
         23        SEND_VAR                                                 !2
         24        SEND_VAL                                                 1
         25        DO_ICALL                                         $16     
         26        ASSIGN                                                   !2, $16
   19    27        INIT_FCALL                                               'str_replace'
         28        SEND_VAL                                                 '%2C'
         29        SEND_VAL                                                 '.'
         30        SEND_VAR                                                 !2
         31        DO_ICALL                                         $18     
         32        ASSIGN                                                   !2, $18
   20    33      > JMP                                                      ->35
   15    34    > > JMP                                                      ->7
         35    >   FE_FREE                                                  $11
   24    36        INIT_FCALL                                               'trim'
         37        SEND_VAR                                                 !2
         38        DO_ICALL                                         $20     
         39        ASSIGN                                                   !5, $20
   25    40        INIT_FCALL                                               'substr'
         41        SEND_VAR                                                 !5
         42        SEND_VAL                                                 -1
         43        DO_ICALL                                         $22     
         44        IS_EQUAL                                                 $22, '.'
         45      > JMPZ                                                     ~23, ->52
   26    46    >   INIT_FCALL                                               'substr'
         47        SEND_VAR                                                 !5
         48        SEND_VAL                                                 0
         49        SEND_VAL                                                 -1
         50        DO_ICALL                                         $24     
         51        ASSIGN                                                   !5, $24
   30    52    >   TYPE_CHECK                                   64          !5
         53      > JMPZ                                                     ~26, ->67
   31    54    >   INIT_FCALL                                               'number_format'
         55        INIT_FCALL                                               'str_replace'
         56        SEND_VAL                                                 '+'
         57        SEND_VAL                                                 ''
         58        SEND_VAR                                                 !5
         59        DO_ICALL                                         $27     
         60        CAST                                          5  ~28     $27
         61        SEND_VAL                                                 ~28
         62        SEND_VAL                                                 2
         63        SEND_VAL                                                 '.'
         64        SEND_VAL                                                 '+'
         65        DO_ICALL                                         $29     
         66        ASSIGN                                                   !5, $29
   33    67    >   INIT_FCALL                                               'is_numeric'
         68        SEND_VAR                                                 !5
         69        DO_ICALL                                         $31     
         70      > JMPZ                                                     $31, ->73
   34    71    >   CONCAT                                           ~32     !5, '+num'
         72        ASSIGN                                                   !5, ~32
   36    73    >   INIT_FCALL                                               'print_r'
         74        SEND_VAR                                                 !5
         75        DO_ICALL                                                 
   37    76        ECHO                                                     '%0A'
   10    77      > JMP                                                      ->2
         78    >   FE_FREE                                                  $7
   38    79      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.29 ms | 1014 KiB | 21 Q