3v4l.org

run code in 500+ 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:  21
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        FRAMELESS_ICALL_2                min                 ~4      5, !1
          7        SEND_VAL                                                     ~4
          8        SEND_VAR                                                     !2
          9        SEND_VAR                                                     !3
         10        DO_ICALL                                             $5      
         11        ASSIGN                                                       !0, $5
    4    12        CONCAT                                               ~7      '%7E', !2
         13        CONCAT                                               ~8      ~7, '%5Cd%7B'
         14        FRAMELESS_ICALL_2                min                 ~9      2, !1
         15        CONCAT                                               ~10     ~8, ~9
         16        CONCAT                                               ~11     ~10, '%7D%5B%5E0%5D%2A%5CK0%2B%24%7E'
         17        FRAMELESS_ICALL_3                preg_replace        ~12     ~11, ''
         18        OP_DATA                                                      !0
         19      > RETURN                                                       ~12
    5    20*     > 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 = 20, Position 2 = 21
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
2 jumps found. (Code = 77) Position 1 = 35, Position 2 = 48
Branch analysis from position: 35
2 jumps found. (Code = 78) Position 1 = 36, Position 2 = 48
Branch analysis from position: 36
2 jumps found. (Code = 46) Position 1 = 38, Position 2 = 40
Branch analysis from position: 38
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 46
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
Branch analysis from position: 48
Branch analysis from position: 48
Branch analysis from position: 9
filename:       /in/iLB63
function name:  dersy
number of ops:  55
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        FRAMELESS_ICALL_2                strpos              ~14     !0, !2
         18        TYPE_CHECK                                        4          ~14
         19      > JMPZ                                                         ~15, ->21
   18    20    > > RETURN                                                       !0
   21    21    >   INIT_FCALL                                                   'explode'
         22        SEND_VAR                                                     !2
         23        SEND_VAR                                                     !0
         24        DO_ICALL                                             $16     
         25        ASSIGN                                                       !4, $16
   22    26        INIT_FCALL                                                   'array_reverse'
         27        INIT_FCALL                                                   'str_split'
         28        FETCH_DIM_R                                          ~18     !4, 1
         29        SEND_VAL                                                     ~18
         30        DO_ICALL                                             $19     
         31        SEND_VAR                                                     $19
         32        DO_ICALL                                             $20     
         33        ASSIGN                                                       !5, $20
   24    34      > FE_RESET_R                                           $22     !5, ->48
         35    > > FE_FETCH_R                                                   $22, !6, ->48
   26    36    >   IS_SMALLER                                           ~23     2, !1
         37      > JMPZ_EX                                              ~23     ~23, ->40
         38    >   IS_IDENTICAL                                         ~24     !6, '0'
         39        BOOL                                                 ~23     ~24
         40    > > JMPZ                                                         ~23, ->46
   27    41    >   FRAMELESS_ICALL_3                substr              ~25     !0, 0
         42        OP_DATA                                                      -1
         43        ASSIGN                                                       !0, ~25
   28    44        PRE_DEC                                                      !1
   26    45      > JMP                                                          ->47
   30    46    > > JMP                                                          ->48
   24    47    > > JMP                                                          ->35
         48    >   FE_FREE                                                      $22
   34    49        INIT_FCALL                                                   'rtrim'
         50        SEND_VAR                                                     !0
         51        SEND_VAR                                                     !2
         52        DO_ICALL                                             $28     
         53      > RETURN                                                       $28
   35    54*     > RETURN                                                       null

End of function dersy

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
280.94 ms | 4700 KiB | 20 Q