3v4l.org

run code in 300+ PHP versions simultaneously
<?php function check_array($arr = false, $index = false){ if(is_array($arr)){ if(is_numeric($index)||is_string($index)){ if(array_key_exists($index, $arr)){ return $arr[$index]; } } } return false; } $types = array( // boolean true, false, // sig int -2, -1, 0, 1, 2, // float 1.111, // string "Punc,tua!ti'o\"n", // array array(), array(0,1,2), array(1 => 0, 1, 2), // object new stdClass, // NULL NULL ); // print heading echo "array\tindex\tresult\n"; $run_once = false; foreach($types as $type){ $line = ''; $myArr = $type; foreach($types as $type){ $myIndex = $type; $line .= gettype($myArr); if(is_scalar($myArr)){ if($myArr === true){ $line .= '("TRUE")'; } else if($myArr === false){ $line .= '("FALSE")'; } else { $line .= "($myArr)"; } } $line .= "\t"; $line .= gettype($myIndex); if(is_scalar($myIndex)){ if($myIndex === true){ $line .= '("TRUE")'; } else if($myIndex === false){ $line .= '("FALSE")'; } else { $line .= "($myIndex)"; } } $line .= "\t"; $result = check_array($myArr, $myIndex); $line .= $result === false ? "FALSE" : $result; $line .= "\n"; echo $line; if(!is_array($myArr)){ break; } } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 20, Position 2 = 80
Branch analysis from position: 20
2 jumps found. (Code = 78) Position 1 = 21, Position 2 = 80
Branch analysis from position: 21
2 jumps found. (Code = 77) Position 1 = 24, Position 2 = 78
Branch analysis from position: 24
2 jumps found. (Code = 78) Position 1 = 25, Position 2 = 78
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 42
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 34
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
2 jumps found. (Code = 43) Position 1 = 47, Position 2 = 59
Branch analysis from position: 47
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 51
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 59
Branch analysis from position: 59
2 jumps found. (Code = 43) Position 1 = 67, Position 2 = 69
Branch analysis from position: 67
1 jumps found. (Code = 42) Position 1 = 70
Branch analysis from position: 70
2 jumps found. (Code = 43) Position 1 = 76, Position 2 = 77
Branch analysis from position: 76
1 jumps found. (Code = 42) Position 1 = 78
Branch analysis from position: 78
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 77
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 69
2 jumps found. (Code = 43) Position 1 = 76, Position 2 = 77
Branch analysis from position: 76
Branch analysis from position: 77
Branch analysis from position: 51
2 jumps found. (Code = 43) Position 1 = 53, Position 2 = 55
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 59
Branch analysis from position: 59
Branch analysis from position: 55
2 jumps found. (Code = 43) Position 1 = 67, Position 2 = 69
Branch analysis from position: 67
Branch analysis from position: 69
Branch analysis from position: 59
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 38
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
Branch analysis from position: 38
2 jumps found. (Code = 43) Position 1 = 47, Position 2 = 59
Branch analysis from position: 47
Branch analysis from position: 59
Branch analysis from position: 42
Branch analysis from position: 78
Branch analysis from position: 78
Branch analysis from position: 80
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 80
filename:       /in/gVCnK
function name:  (null)
number of ops:  82
compiled vars:  !0 = $types, !1 = $run_once, !2 = $type, !3 = $line, !4 = $myArr, !5 = $myIndex, !6 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   INIT_ARRAY                                       ~7      <true>
          1        ADD_ARRAY_ELEMENT                                ~7      <false>
          2        ADD_ARRAY_ELEMENT                                ~7      -2
          3        ADD_ARRAY_ELEMENT                                ~7      -1
   21     4        ADD_ARRAY_ELEMENT                                ~7      0
   22     5        ADD_ARRAY_ELEMENT                                ~7      1
   23     6        ADD_ARRAY_ELEMENT                                ~7      2
   25     7        ADD_ARRAY_ELEMENT                                ~7      1.111
   27     8        ADD_ARRAY_ELEMENT                                ~7      'Punc%2Ctua%21ti%27o%22n'
   16     9        ADD_ARRAY_ELEMENT                                ~7      <array>
         10        ADD_ARRAY_ELEMENT                                ~7      <array>
         11        ADD_ARRAY_ELEMENT                                ~7      <array>
   33    12        NEW                                              $8      'stdClass'
         13        DO_FCALL                                      0          
         14        ADD_ARRAY_ELEMENT                                ~7      $8
   16    15        ADD_ARRAY_ELEMENT                                ~7      null
   14    16        ASSIGN                                                   !0, ~7
   39    17        ECHO                                                     'array%09index%09result%0A'
   40    18        ASSIGN                                                   !1, <false>
   42    19      > FE_RESET_R                                       $12     !0, ->80
         20    > > FE_FETCH_R                                               $12, !2, ->80
   43    21    >   ASSIGN                                                   !3, ''
   44    22        ASSIGN                                                   !4, !2
   45    23      > FE_RESET_R                                       $15     !0, ->78
         24    > > FE_FETCH_R                                               $15, !2, ->78
   46    25    >   ASSIGN                                                   !5, !2
   48    26        GET_TYPE                                         ~17     !4
         27        ASSIGN_OP                                     8          !3, ~17
   49    28        TYPE_CHECK                                  124          !4
         29      > JMPZ                                                     ~19, ->42
   50    30    >   TYPE_CHECK                                    8          !4
         31      > JMPZ                                                     ~20, ->34
         32    >   ASSIGN_OP                                     8          !3, '%28%22TRUE%22%29'
         33      > JMP                                                      ->42
   51    34    >   TYPE_CHECK                                    4          !4
         35      > JMPZ                                                     ~22, ->38
         36    >   ASSIGN_OP                                     8          !3, '%28%22FALSE%22%29'
         37      > JMP                                                      ->42
   52    38    >   ROPE_INIT                                     3  ~25     '%28'
         39        ROPE_ADD                                      1  ~25     ~25, !4
         40        ROPE_END                                      2  ~24     ~25, '%29'
         41        ASSIGN_OP                                     8          !3, ~24
   54    42    >   ASSIGN_OP                                     8          !3, '%09'
   56    43        GET_TYPE                                         ~29     !5
         44        ASSIGN_OP                                     8          !3, ~29
   57    45        TYPE_CHECK                                  124          !5
         46      > JMPZ                                                     ~31, ->59
   58    47    >   TYPE_CHECK                                    8          !5
         48      > JMPZ                                                     ~32, ->51
         49    >   ASSIGN_OP                                     8          !3, '%28%22TRUE%22%29'
         50      > JMP                                                      ->59
   59    51    >   TYPE_CHECK                                    4          !5
         52      > JMPZ                                                     ~34, ->55
         53    >   ASSIGN_OP                                     8          !3, '%28%22FALSE%22%29'
         54      > JMP                                                      ->59
   60    55    >   ROPE_INIT                                     3  ~37     '%28'
         56        ROPE_ADD                                      1  ~37     ~37, !5
         57        ROPE_END                                      2  ~36     ~37, '%29'
         58        ASSIGN_OP                                     8          !3, ~36
   62    59    >   ASSIGN_OP                                     8          !3, '%09'
   64    60        INIT_FCALL                                               'check_array'
         61        SEND_VAR                                                 !4
         62        SEND_VAR                                                 !5
         63        DO_FCALL                                      0  $41     
         64        ASSIGN                                                   !6, $41
   65    65        TYPE_CHECK                                    4          !6
         66      > JMPZ                                                     ~43, ->69
         67    >   QM_ASSIGN                                        ~44     'FALSE'
         68      > JMP                                                      ->70
         69    >   QM_ASSIGN                                        ~44     !6
         70    >   ASSIGN_OP                                     8          !3, ~44
   66    71        ASSIGN_OP                                     8          !3, '%0A'
   67    72        ECHO                                                     !3
   69    73        TYPE_CHECK                                  128  ~47     !4
         74        BOOL_NOT                                         ~48     ~47
         75      > JMPZ                                                     ~48, ->77
         76    > > JMP                                                      ->78
   45    77    > > JMP                                                      ->24
         78    >   FE_FREE                                                  $15
   42    79      > JMP                                                      ->20
         80    >   FE_FREE                                                  $12
   71    81      > RETURN                                                   1

Function check_array:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 15
Branch analysis from position: 4
2 jumps found. (Code = 47) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 15
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 15
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
Branch analysis from position: 10
Branch analysis from position: 15
filename:       /in/gVCnK
function name:  check_array
number of ops:  17
compiled vars:  !0 = $arr, !1 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV_INIT                                        !0      <false>
          1        RECV_INIT                                        !1      <false>
    4     2        TYPE_CHECK                                  128          !0
          3      > JMPZ                                                     ~2, ->15
    5     4    >   INIT_FCALL                                               'is_numeric'
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $3      
          7      > JMPNZ_EX                                         ~4      $3, ->10
          8    >   TYPE_CHECK                                   64  ~5      !1
          9        BOOL                                             ~4      ~5
         10    > > JMPZ                                                     ~4, ->15
    6    11    >   ARRAY_KEY_EXISTS                                         !1, !0
         12      > JMPZ                                                     ~6, ->15
    7    13    >   FETCH_DIM_R                                      ~7      !0, !1
         14      > RETURN                                                   ~7
   11    15    > > RETURN                                                   <false>
   12    16*     > RETURN                                                   null

End of function check_array

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.55 ms | 1407 KiB | 19 Q