3v4l.org

run code in 300+ PHP versions simultaneously
<?php function ruleTypes() { $ruleArray = []; $types = [0 => ['type' => 'required', 'value_1' => null, 'value_2'=> null], ['type' => 'min', 'value_1' => 3, 'value_2'=> 0, 'value_2'=> null], ['type' => 'max', 'value_1' => 10, 'value_2'=> null], ['type' => 'between', 'value_1' => 10, 'value_2'=> 100] ]; $arr = []; foreach ($types as $type) { if (\in_array($type['type'], getNoValidationValueRequired())){ $ruleArray[] = $type['type']; }else { $ruleArray[] = sortRulesOrder($type); // $value . ':' . $value } } return implode('|', $ruleArray); } function sortRulesOrder(array $type) { if($type['type']){ if($type['value_1'] && $type['value_2']) { return $type['type'] . ':' . $type['value_1'] .',' .$type['value_2']; } else { $value = $type['value_1'] ? $type['value_1'] : $type['value_2']; return $type['type'] . ':' . $value; } } } function getNoValidationValueRequired() { return ['required']; } var_dump(ruleTypes());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/15Cjd
function name:  (null)
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'ruletypes'
          2        DO_FCALL                                      0  $0      
          3        SEND_VAR                                                 $0
          4        DO_ICALL                                                 
          5      > RETURN                                                   1

Function ruletypes:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 23
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 23
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 17
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
filename:       /in/15Cjd
function name:  ruleTypes
number of ops:  30
compiled vars:  !0 = $ruleArray, !1 = $types, !2 = $arr, !3 = $type
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   ASSIGN                                                   !0, <array>
    7     1        ASSIGN                                                   !1, <array>
   13     2        ASSIGN                                                   !2, <array>
   14     3      > FE_RESET_R                                       $7      !1, ->23
          4    > > FE_FETCH_R                                               $7, !3, ->23
   15     5    >   INIT_FCALL                                               'in_array'
          6        FETCH_DIM_R                                      ~8      !3, 'type'
          7        SEND_VAL                                                 ~8
          8        INIT_FCALL_BY_NAME                                       'getNoValidationValueRequired'
          9        DO_FCALL                                      0  $9      
         10        SEND_VAR                                                 $9
         11        DO_ICALL                                         $10     
         12      > JMPZ                                                     $10, ->17
   16    13    >   FETCH_DIM_R                                      ~12     !3, 'type'
         14        ASSIGN_DIM                                               !0
         15        OP_DATA                                                  ~12
         16      > JMP                                                      ->22
   18    17    >   INIT_FCALL_BY_NAME                                       'sortRulesOrder'
         18        SEND_VAR_EX                                              !3
         19        DO_FCALL                                      0  $14     
         20        ASSIGN_DIM                                               !0
         21        OP_DATA                                                  $14
   14    22    > > JMP                                                      ->4
         23    >   FE_FREE                                                  $7
   21    24        INIT_FCALL                                               'implode'
         25        SEND_VAL                                                 '%7C'
         26        SEND_VAR                                                 !0
         27        DO_ICALL                                         $15     
         28      > RETURN                                                   $15
   22    29*     > RETURN                                                   null

End of function ruletypes

Function sortrulesorder:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 29
Branch analysis from position: 3
2 jumps found. (Code = 46) Position 1 = 5, Position 2 = 7
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 17
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 22
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/15Cjd
function name:  sortRulesOrder
number of ops:  30
compiled vars:  !0 = $type, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   26     1        FETCH_DIM_R                                      ~2      !0, 'type'
          2      > JMPZ                                                     ~2, ->29
   28     3    >   FETCH_DIM_R                                      ~3      !0, 'value_1'
          4      > JMPZ_EX                                          ~3      ~3, ->7
          5    >   FETCH_DIM_R                                      ~4      !0, 'value_2'
          6        BOOL                                             ~3      ~4
          7    > > JMPZ                                                     ~3, ->17
   30     8    >   FETCH_DIM_R                                      ~5      !0, 'type'
          9        CONCAT                                           ~6      ~5, '%3A'
         10        FETCH_DIM_R                                      ~7      !0, 'value_1'
         11        CONCAT                                           ~8      ~6, ~7
         12        CONCAT                                           ~9      ~8, '%2C'
         13        FETCH_DIM_R                                      ~10     !0, 'value_2'
         14        CONCAT                                           ~11     ~9, ~10
         15      > RETURN                                                   ~11
         16*       JMP                                                      ->29
   32    17    >   FETCH_DIM_R                                      ~12     !0, 'value_1'
         18      > JMPZ                                                     ~12, ->22
         19    >   FETCH_DIM_R                                      ~13     !0, 'value_1'
         20        QM_ASSIGN                                        ~14     ~13
         21      > JMP                                                      ->24
         22    >   FETCH_DIM_R                                      ~15     !0, 'value_2'
         23        QM_ASSIGN                                        ~14     ~15
         24    >   ASSIGN                                                   !1, ~14
   33    25        FETCH_DIM_R                                      ~17     !0, 'type'
         26        CONCAT                                           ~18     ~17, '%3A'
         27        CONCAT                                           ~19     ~18, !1
         28      > RETURN                                                   ~19
   37    29    > > RETURN                                                   null

End of function sortrulesorder

Function getnovalidationvaluerequired:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/15Cjd
function name:  getNoValidationValueRequired
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E > > RETURN                                                   <array>
   42     1*     > RETURN                                                   null

End of function getnovalidationvaluerequired

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
174.04 ms | 1407 KiB | 20 Q