3v4l.org

run code in 300+ PHP versions simultaneously
<?php function ascending_array($array){ if (!is_array($array)){ $array = explode(",", $array); } $new = array(); $flag = true; iter: $array = array_values($array); // recount array values with new offsets (isset($min["max"])) ? $min["value"] = $min["max"] : $min["value"] = $array[0]; $min["offset"] = 0; for ($i=0;$i<count($array);$i++){ if ($array[$i] < $min["value"]){ // redefine min values each time if statement executed $min["value"] = $array[$i]; $min["offset"] = $i; } if ($flag){ // execute only first time if ($array[$i] > $min["value"]){ // define max value from array $min["max"] = $array[$i]; } $flag = false; } if ($i === (count($array)-1)){ // last array element array_push($new,$min["value"]); unset($array[$min["offset"]]); } } if (count($array)!=0){ goto iter; } print_r($new); } $arr = array(50,25,98,45); print_r(ascending_array($arr)); // 25 45 50 98
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/H1Hmj
function name:  (null)
number of ops:  8
compiled vars:  !0 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   ASSIGN                                                   !0, <array>
   44     1        INIT_FCALL                                               'print_r'
          2        INIT_FCALL                                               'ascending_array'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Function ascending_array:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 9
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 22
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 61
Branch analysis from position: 61
2 jumps found. (Code = 44) Position 1 = 64, Position 2 = 31
Branch analysis from position: 64
2 jumps found. (Code = 43) Position 1 = 67, Position 2 = 68
Branch analysis from position: 67
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 68
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 40
Branch analysis from position: 35
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 49
Branch analysis from position: 41
2 jumps found. (Code = 43) Position 1 = 45, Position 2 = 48
Branch analysis from position: 45
2 jumps found. (Code = 43) Position 1 = 53, Position 2 = 60
Branch analysis from position: 53
2 jumps found. (Code = 44) Position 1 = 64, Position 2 = 31
Branch analysis from position: 64
Branch analysis from position: 31
Branch analysis from position: 60
Branch analysis from position: 48
Branch analysis from position: 49
Branch analysis from position: 40
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 61
Branch analysis from position: 61
Branch analysis from position: 9
filename:       /in/H1Hmj
function name:  ascending_array
number of ops:  72
compiled vars:  !0 = $array, !1 = $new, !2 = $flag, !3 = $min, !4 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        TYPE_CHECK                                  128  ~5      !0
          2        BOOL_NOT                                         ~6      ~5
          3      > JMPZ                                                     ~6, ->9
    5     4    >   INIT_FCALL                                               'explode'
          5        SEND_VAL                                                 '%2C'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $7      
          8        ASSIGN                                                   !0, $7
    8     9    >   ASSIGN                                                   !1, <array>
    9    10        ASSIGN                                                   !2, <true>
   12    11    >   INIT_FCALL                                               'array_values'
         12        SEND_VAR                                                 !0
         13        DO_ICALL                                         $11     
         14        ASSIGN                                                   !0, $11
   14    15        ISSET_ISEMPTY_DIM_OBJ                         0          !3, 'max'
         16      > JMPZ                                                     ~13, ->22
         17    >   FETCH_DIM_R                                      ~15     !3, 'max'
         18        ASSIGN_DIM                                       ~14     !3, 'value'
         19        OP_DATA                                                  ~15
         20        QM_ASSIGN                                        ~16     ~14
         21      > JMP                                                      ->26
         22    >   FETCH_DIM_R                                      ~18     !0, 0
         23        ASSIGN_DIM                                       ~17     !3, 'value'
         24        OP_DATA                                                  ~18
         25        QM_ASSIGN                                        ~16     ~17
         26    >   FREE                                                     ~16
   15    27        ASSIGN_DIM                                               !3, 'offset'
         28        OP_DATA                                                  0
   17    29        ASSIGN                                                   !4, 0
         30      > JMP                                                      ->61
   18    31    >   FETCH_DIM_R                                      ~21     !0, !4
         32        FETCH_DIM_R                                      ~22     !3, 'value'
         33        IS_SMALLER                                               ~21, ~22
         34      > JMPZ                                                     ~23, ->40
   19    35    >   FETCH_DIM_R                                      ~25     !0, !4
         36        ASSIGN_DIM                                               !3, 'value'
         37        OP_DATA                                                  ~25
   20    38        ASSIGN_DIM                                               !3, 'offset'
         39        OP_DATA                                                  !4
   23    40    > > JMPZ                                                     !2, ->49
   24    41    >   FETCH_DIM_R                                      ~27     !0, !4
         42        FETCH_DIM_R                                      ~28     !3, 'value'
         43        IS_SMALLER                                               ~28, ~27
         44      > JMPZ                                                     ~29, ->48
   25    45    >   FETCH_DIM_R                                      ~31     !0, !4
         46        ASSIGN_DIM                                               !3, 'max'
         47        OP_DATA                                                  ~31
   27    48    >   ASSIGN                                                   !2, <false>
   30    49    >   COUNT                                            ~33     !0
         50        SUB                                              ~34     ~33, 1
         51        IS_IDENTICAL                                             !4, ~34
         52      > JMPZ                                                     ~35, ->60
   31    53    >   INIT_FCALL                                               'array_push'
         54        SEND_REF                                                 !1
         55        FETCH_DIM_R                                      ~36     !3, 'value'
         56        SEND_VAL                                                 ~36
         57        DO_ICALL                                                 
   32    58        FETCH_DIM_R                                      ~38     !3, 'offset'
         59        UNSET_DIM                                                !0, ~38
   17    60    >   PRE_INC                                                  !4
         61    >   COUNT                                            ~40     !0
         62        IS_SMALLER                                               !4, ~40
         63      > JMPNZ                                                    ~41, ->31
   36    64    >   COUNT                                            ~42     !0
         65        IS_NOT_EQUAL                                             ~42, 0
         66      > JMPZ                                                     ~43, ->68
   37    67    > > JMP                                                      ->11
   39    68    >   INIT_FCALL                                               'print_r'
         69        SEND_VAR                                                 !1
         70        DO_ICALL                                                 
   40    71      > RETURN                                                   null

End of function ascending_array

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.76 ms | 1407 KiB | 22 Q