3v4l.org

run code in 300+ PHP versions simultaneously
<?php function createValidator($key, $value) { return fn ($x) => is_array($x) && $x[$key] === $value; } $x = [ 123 => ['name' => 'xxx'], 456 => ['name' => 'yyy'], ]; echo \array_key_exists(123, $x) ? 'yes' : 'no'; echo "\n"; $x = [ ['id' => 123, 'name' => 'xxx'], ['id' => 456, 'name' => 'yyy'], ]; $y = \array_filter($x, createValidator('id', 123)); echo \count($y) ? 'yes' : 'no'; // if array child id === 123 in any of the children, // then echo yes, // (without using a loop, and by using an array function)
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 5
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 22
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
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: 5
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 22
Branch analysis from position: 20
Branch analysis from position: 22
filename:       /in/q84Ok
function name:  (null)
number of ops:  25
compiled vars:  !0 = $x, !1 = $y
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   ASSIGN                                                   !0, <array>
   14     1        ARRAY_KEY_EXISTS                                         123, !0
          2      > JMPZ                                                     ~3, ->5
          3    >   QM_ASSIGN                                        ~4      'yes'
          4      > JMP                                                      ->6
          5    >   QM_ASSIGN                                        ~4      'no'
          6    >   ECHO                                                     ~4
   15     7        ECHO                                                     '%0A'
   17     8        ASSIGN                                                   !0, <array>
   22     9        INIT_FCALL                                               'array_filter'
         10        SEND_VAR                                                 !0
         11        INIT_FCALL                                               'createvalidator'
         12        SEND_VAL                                                 'id'
         13        SEND_VAL                                                 123
         14        DO_FCALL                                      0  $6      
         15        SEND_VAR                                                 $6
         16        DO_ICALL                                         $7      
         17        ASSIGN                                                   !1, $7
   25    18        COUNT                                            ~9      !1
         19      > JMPZ                                                     ~9, ->22
         20    >   QM_ASSIGN                                        ~10     'yes'
         21      > JMP                                                      ->23
         22    >   QM_ASSIGN                                        ~10     'no'
         23    >   ECHO                                                     ~10
   30    24      > RETURN                                                   1

Function createvalidator:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/q84Ok
function name:  createValidator
number of ops:  7
compiled vars:  !0 = $key, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fq84Ok%3A5%240'
          3        BIND_LEXICAL                                             ~2, !0
          4        BIND_LEXICAL                                             ~2, !1
          5      > RETURN                                                   ~2
    6     6*     > RETURN                                                   null

End of function createvalidator

Function %00%7Bclosure%7D%2Fin%2Fq84Ok%3A5%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/q84Ok
function name:  {closure}
number of ops:  10
compiled vars:  !0 = $x, !1 = $key, !2 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
          3        TYPE_CHECK                                  128  ~3      !0
          4      > JMPZ_EX                                          ~3      ~3, ->8
          5    >   FETCH_DIM_R                                      ~4      !0, !1
          6        IS_IDENTICAL                                     ~5      !2, ~4
          7        BOOL                                             ~3      ~5
          8    > > RETURN                                                   ~3
          9*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Fq84Ok%3A5%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.82 ms | 1407 KiB | 16 Q