3v4l.org

run code in 300+ PHP versions simultaneously
<?php function in_arrayi($needle, array $haystack, bool $strict = false): bool { if (!is_scalar($needle)) { // throw exception or something because of unsuitable data type } $needle = strtolower($needle); foreach ($haystack as $value) { if (!is_scalar($value)) { continue; } elseif ($strict && strtolower($value) === $needle) { return true; } elseif (!$strict && strtolower($value) == $needle) { return true; } } return false; } $haystack = array('one', 'two', 'three', 'four'); $test_needles = ['onE', 'tWo', 'THREE', 'four', 'five']; foreach ($test_needles as $needle) { echo $needle . ': ' . (in_arrayi($needle, $haystack) ? 'found' : 'missing') . "\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 17
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 17
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/WCTi2
function name:  (null)
number of ops:  19
compiled vars:  !0 = $haystack, !1 = $test_needles, !2 = $needle
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   ASSIGN                                                   !0, <array>
   22     1        ASSIGN                                                   !1, <array>
   24     2      > FE_RESET_R                                       $5      !1, ->17
          3    > > FE_FETCH_R                                               $5, !2, ->17
   25     4    >   CONCAT                                           ~6      !2, '%3A+'
          5        INIT_FCALL                                               'in_arrayi'
          6        SEND_VAR                                                 !2
          7        SEND_VAR                                                 !0
          8        DO_FCALL                                      0  $7      
          9      > JMPZ                                                     $7, ->12
         10    >   QM_ASSIGN                                        ~8      'found'
         11      > JMP                                                      ->13
         12    >   QM_ASSIGN                                        ~8      'missing'
         13    >   CONCAT                                           ~9      ~6, ~8
         14        CONCAT                                           ~10     ~9, '%0A'
         15        ECHO                                                     ~10
   24    16      > JMP                                                      ->3
         17    >   FE_FREE                                                  $5
   26    18      > RETURN                                                   1

Function in_arrayi:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 6
Branch analysis from position: 6
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 38
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 38
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 17
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 17
2 jumps found. (Code = 46) Position 1 = 18, Position 2 = 23
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 27
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
2 jumps found. (Code = 46) Position 1 = 29, Position 2 = 34
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 37
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 34
Branch analysis from position: 23
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
Branch analysis from position: 6
filename:       /in/WCTi2
function name:  in_arrayi
number of ops:  42
compiled vars:  !0 = $needle, !1 = $haystack, !2 = $strict, !3 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      <false>
    4     3        TYPE_CHECK                                  124  ~4      !0
          4        BOOL_NOT                                         ~5      ~4
          5      > JMPZ                                                     ~5, ->6
    7     6    >   INIT_FCALL                                               'strtolower'
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $6      
          9        ASSIGN                                                   !0, $6
    9    10      > FE_RESET_R                                       $8      !1, ->38
         11    > > FE_FETCH_R                                               $8, !3, ->38
   10    12    >   TYPE_CHECK                                  124  ~9      !3
         13        BOOL_NOT                                         ~10     ~9
         14      > JMPZ                                                     ~10, ->17
   11    15    > > JMP                                                      ->11
         16*       JMP                                                      ->37
   12    17    > > JMPZ_EX                                          ~11     !2, ->23
         18    >   INIT_FCALL                                               'strtolower'
         19        SEND_VAR                                                 !3
         20        DO_ICALL                                         $12     
         21        IS_IDENTICAL                                     ~13     !0, $12
         22        BOOL                                             ~11     ~13
         23    > > JMPZ                                                     ~11, ->27
   13    24    >   FE_FREE                                                  $8
         25      > RETURN                                                   <true>
         26*       JMP                                                      ->37
   14    27    >   BOOL_NOT                                         ~14     !2
         28      > JMPZ_EX                                          ~14     ~14, ->34
         29    >   INIT_FCALL                                               'strtolower'
         30        SEND_VAR                                                 !3
         31        DO_ICALL                                         $15     
         32        IS_EQUAL                                         ~16     !0, $15
         33        BOOL                                             ~14     ~16
         34    > > JMPZ                                                     ~14, ->37
   15    35    >   FE_FREE                                                  $8
         36      > RETURN                                                   <true>
    9    37    > > JMP                                                      ->11
         38    >   FE_FREE                                                  $8
   18    39      > RETURN                                                   <false>
   19    40*       VERIFY_RETURN_TYPE                                       
         41*     > RETURN                                                   null

End of function in_arrayi

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.48 ms | 1403 KiB | 16 Q