3v4l.org

run code in 300+ PHP versions simultaneously
<?php function mickmackusa($number, $decimals = 2, $dec_point = ',', $thousands_sep = ' ') { $number = number_format($number, min(5, $decimals), $dec_point, $thousands_sep); // round to decimal max return preg_replace("~".$dec_point."\d{".min(2, $decimals)."}[^0]*\K0+$~", '', $number); // trim zeros (if any, beyond minimum allowance) from right side of decimal character } function dersy($number, $decimals=2, $dec_point = ',', $thousands_sep = ' ') { $decimals = (int)$decimals; if($decimals > 5) { $decimals = 5; //Maximum decimals limit.. } $number = number_format((float)$number, $decimals, $dec_point, $thousands_sep); if(strpos($number, $dec_point) === false) { return $number; //No decimal values.. } $splArr = explode($dec_point, $number); $split = array_reverse(str_split($splArr[1])); foreach($split as $cleanNum) { if($decimals > 2 && $cleanNum === '0') { //Keep minimum two decimals. $number = substr($number, 0, -1); $decimals--; } else { break; //Found a non zero number. } } return rtrim($number,$dec_point); } $test = [ '1.01', '1.044', '0.240000', '0.200', '0.24540', '0.24546', '6500.00', '3760.54', '3760.000000000', '0.04000', '1.000000', '1.000005' ]; for ($x=0; $x<7; ++$x) { foreach ($test as $number) { $mickmackusa = mickmackusa($number, $x); $dersy = dersy($number, $x); echo "$number & $x -> Assert: $mickmackusa (Expect: $dersy) "; if ($mickmackusa === $dersy) { echo "IDENTICAL\n"; } else { echo "FAILURE\n"; } } }

Abusive script

This script was stopped while abusing our resources

Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
2 jumps found. (Code = 44) Position 1 = 34, Position 2 = 3
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 30
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 30
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 28
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 34, Position 2 = 3
Branch analysis from position: 34
Branch analysis from position: 3
Branch analysis from position: 30
filename:       /in/iLB63
function name:  (null)
number of ops:  35
compiled vars:  !0 = $test, !1 = $x, !2 = $number, !3 = $mickmackusa, !4 = $dersy
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   ASSIGN                                                   !0, <array>
   52     1        ASSIGN                                                   !1, 0
          2      > JMP                                                      ->32
   53     3    > > FE_RESET_R                                       $7      !0, ->30
          4    > > FE_FETCH_R                                               $7, !2, ->30
   54     5    >   INIT_FCALL                                               'mickmackusa'
          6        SEND_VAR                                                 !2
          7        SEND_VAR                                                 !1
          8        DO_FCALL                                      0  $8      
          9        ASSIGN                                                   !3, $8
   55    10        INIT_FCALL                                               'dersy'
         11        SEND_VAR                                                 !2
         12        SEND_VAR                                                 !1
         13        DO_FCALL                                      0  $10     
         14        ASSIGN                                                   !4, $10
   56    15        ROPE_INIT                                     8  ~13     !2
         16        ROPE_ADD                                      1  ~13     ~13, '+%26+'
         17        ROPE_ADD                                      2  ~13     ~13, !1
         18        ROPE_ADD                                      3  ~13     ~13, '+-%3E+Assert%3A+'
         19        ROPE_ADD                                      4  ~13     ~13, !3
         20        ROPE_ADD                                      5  ~13     ~13, '+%28Expect%3A+'
         21        ROPE_ADD                                      6  ~13     ~13, !4
         22        ROPE_END                                      7  ~12     ~13, '%29+'
         23        ECHO                                                     ~12
   57    24        IS_IDENTICAL                                             !3, !4
         25      > JMPZ                                                     ~17, ->28
   58    26    >   ECHO                                                     'IDENTICAL%0A'
   57    27      > JMP                                                      ->29
   60    28    >   ECHO                                                     'FAILURE%0A'
   53    29    > > JMP                                                      ->4
         30    >   FE_FREE                                                  $7
   52    31        PRE_INC                                                  !1
         32    >   IS_SMALLER                                               !1, 7
         33      > JMPNZ                                                    ~19, ->3
   63    34    > > RETURN                                                   1

Function mickmackusa:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iLB63
function name:  mickmackusa
number of ops:  30
compiled vars:  !0 = $number, !1 = $decimals, !2 = $dec_point, !3 = $thousands_sep
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      2
          2        RECV_INIT                                        !2      '%2C'
          3        RECV_INIT                                        !3      '+'
    3     4        INIT_FCALL                                               'number_format'
          5        SEND_VAR                                                 !0
          6        INIT_FCALL                                               'min'
          7        SEND_VAL                                                 5
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                         $4      
         10        SEND_VAR                                                 $4
         11        SEND_VAR                                                 !2
         12        SEND_VAR                                                 !3
         13        DO_ICALL                                         $5      
         14        ASSIGN                                                   !0, $5
    4    15        INIT_FCALL                                               'preg_replace'
         16        CONCAT                                           ~7      '%7E', !2
         17        CONCAT                                           ~8      ~7, '%5Cd%7B'
         18        INIT_FCALL                                               'min'
         19        SEND_VAL                                                 2
         20        SEND_VAR                                                 !1
         21        DO_ICALL                                         $9      
         22        CONCAT                                           ~10     ~8, $9
         23        CONCAT                                           ~11     ~10, '%7D%5B%5E0%5D%2A%5CK0%2B%24%7E'
         24        SEND_VAL                                                 ~11
         25        SEND_VAL                                                 ''
         26        SEND_VAR                                                 !0
         27        DO_ICALL                                         $12     
         28      > RETURN                                                   $12
    5    29*     > RETURN                                                   null

End of function mickmackusa

Function dersy:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 9
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 24
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
2 jumps found. (Code = 77) Position 1 = 38, Position 2 = 54
Branch analysis from position: 38
2 jumps found. (Code = 78) Position 1 = 39, Position 2 = 54
Branch analysis from position: 39
2 jumps found. (Code = 46) Position 1 = 41, Position 2 = 43
Branch analysis from position: 41
2 jumps found. (Code = 43) Position 1 = 44, Position 2 = 52
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 54
Branch analysis from position: 54
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 43
Branch analysis from position: 54
Branch analysis from position: 54
Branch analysis from position: 9
filename:       /in/iLB63
function name:  dersy
number of ops:  61
compiled vars:  !0 = $number, !1 = $decimals, !2 = $dec_point, !3 = $thousands_sep, !4 = $splArr, !5 = $split, !6 = $cleanNum
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      2
          2        RECV_INIT                                        !2      '%2C'
          3        RECV_INIT                                        !3      '+'
    9     4        CAST                                          4  ~7      !1
          5        ASSIGN                                                   !1, ~7
   11     6        IS_SMALLER                                               5, !1
          7      > JMPZ                                                     ~9, ->9
   12     8    >   ASSIGN                                                   !1, 5
   15     9    >   INIT_FCALL                                               'number_format'
         10        CAST                                          5  ~11     !0
         11        SEND_VAL                                                 ~11
         12        SEND_VAR                                                 !1
         13        SEND_VAR                                                 !2
         14        SEND_VAR                                                 !3
         15        DO_ICALL                                         $12     
         16        ASSIGN                                                   !0, $12
   17    17        INIT_FCALL                                               'strpos'
         18        SEND_VAR                                                 !0
         19        SEND_VAR                                                 !2
         20        DO_ICALL                                         $14     
         21        TYPE_CHECK                                    4          $14
         22      > JMPZ                                                     ~15, ->24
   18    23    > > RETURN                                                   !0
   21    24    >   INIT_FCALL                                               'explode'
         25        SEND_VAR                                                 !2
         26        SEND_VAR                                                 !0
         27        DO_ICALL                                         $16     
         28        ASSIGN                                                   !4, $16
   22    29        INIT_FCALL                                               'array_reverse'
         30        INIT_FCALL                                               'str_split'
         31        FETCH_DIM_R                                      ~18     !4, 1
         32        SEND_VAL                                                 ~18
         33        DO_ICALL                                         $19     
         34        SEND_VAR                                                 $19
         35        DO_ICALL                                         $20     
         36        ASSIGN                                                   !5, $20
   24    37      > FE_RESET_R                                       $22     !5, ->54
         38    > > FE_FETCH_R                                               $22, !6, ->54
   26    39    >   IS_SMALLER                                       ~23     2, !1
         40      > JMPZ_EX                                          ~23     ~23, ->43
         41    >   IS_IDENTICAL                                     ~24     !6, '0'
         42        BOOL                                             ~23     ~24
         43    > > JMPZ                                                     ~23, ->52
   27    44    >   INIT_FCALL                                               'substr'
         45        SEND_VAR                                                 !0
         46        SEND_VAL                                                 0
         47        SEND_VAL                                                 -1
         48        DO_ICALL                                         $25     
         49        ASSIGN                                                   !0, $25
   28    50        PRE_DEC                                                  !1
   26    51      > JMP                                                      ->53
   30    52    > > JMP                                                      ->54
   24    53    > > JMP                                                      ->38
         54    >   FE_FREE                                                  $22
   34    55        INIT_FCALL                                               'rtrim'
         56        SEND_VAR                                                 !0
         57        SEND_VAR                                                 !2
         58        DO_ICALL                                         $28     
         59      > RETURN                                                   $28
   35    60*     > RETURN                                                   null

End of function dersy

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
299.98 ms | 1035 KiB | 24 Q