3v4l.org

run code in 500+ PHP versions simultaneously
<?php $data=array(array('name'=>'ahmed','job'=>'engineer','age'=>25,'hobbies'=>array('drawing','swimming','reading'),'skills'=>array('coding','fasting learning','teaching')),array('name'=>'Sara','job'=>'designer','age'=>19,'skills'=>array('fast learning')),array('name'=>'Ali','age'=>25,'city'=>'cairo'),array('name'=>'Hossam','job'=>'accountant','age'=>25,'city'=>'zagazig'),array('name'=>'Esraa','job'=>'Designer','age'=>23,'city'=>'zagazig','hobbies'=>array('writing','reading'),'skills'=>array('coding','teaching')),); $search_string = 'reading'; $criteria = 'hobbies'; $results = array_filter($data, function($e) use ($search_string, $criteria) { return ( !empty($e[$criteria]) && (!is_array($e[$criteria]) ? (strpos($e[$criteria], $search_string) !== false) : (in_array($search_string, $e[$criteria])) ) ); }); if(!empty($results)) { echo 'Number of results: ' , count($results), PHP_EOL, ' Result ', PHP_EOL; foreach($results as $r) { echo " Name: {$r['name']} Job: {$r['job']} Age: {$r['age']} ", PHP_EOL; echo !empty($r['hobbies']) ? PHP_EOL . 'Hobbies: ' . PHP_EOL . implode(PHP_EOL, $r['hobbies']) : ''; } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 46
Branch analysis from position: 14
2 jumps found. (Code = 77) Position 1 = 21, Position 2 = 45
Branch analysis from position: 21
2 jumps found. (Code = 78) Position 1 = 22, Position 2 = 45
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 42
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 45
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 45
Branch analysis from position: 46
filename:       /in/3vCFe
function name:  (null)
number of ops:  47
compiled vars:  !0 = $data, !1 = $search_string, !2 = $criteria, !3 = $results, !4 = $r
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
    5     1        ASSIGN                                                       !1, 'reading'
    6     2        ASSIGN                                                       !2, 'hobbies'
    7     3        INIT_FCALL                                                   'array_filter'
          4        SEND_VAR                                                     !0
          5        DECLARE_LAMBDA_FUNCTION                              ~8      [0]
          6        BIND_LEXICAL                                                 ~8, !1
          7        BIND_LEXICAL                                                 ~8, !2
   15     8        SEND_VAL                                                     ~8
    7     9        DO_ICALL                                             $9      
         10        ASSIGN                                                       !3, $9
   17    11        ISSET_ISEMPTY_CV                                     ~11     !3
         12        BOOL_NOT                                             ~12     ~11
         13      > JMPZ                                                         ~12, ->46
   18    14    >   ECHO                                                         'Number+of+results%3A+'
         15        COUNT                                                ~13     !3
         16        ECHO                                                         ~13
         17        ECHO                                                         '%0A'
         18        ECHO                                                         '+Result+'
         19        ECHO                                                         '%0A'
   19    20      > FE_RESET_R                                           $14     !3, ->45
         21    > > FE_FETCH_R                                                   $14, !4, ->45
   20    22    >   ROPE_INIT                                         7  ~19     '%0A%09%09Name%3A+'
   21    23        FETCH_DIM_R                                          ~15     !4, 'name'
         24        ROPE_ADD                                          1  ~19     ~19, ~15
         25        ROPE_ADD                                          2  ~19     ~19, '%0A%09%09Job%3A+'
   22    26        FETCH_DIM_R                                          ~16     !4, 'job'
         27        ROPE_ADD                                          3  ~19     ~19, ~16
         28        ROPE_ADD                                          4  ~19     ~19, '%0A%09%09Age%3A+'
   23    29        FETCH_DIM_R                                          ~17     !4, 'age'
         30        ROPE_ADD                                          5  ~19     ~19, ~17
         31        ROPE_END                                          6  ~18     ~19, '%0A%09%09'
         32        ECHO                                                         ~18
   24    33        ECHO                                                         '%0A'
   25    34        ISSET_ISEMPTY_DIM_OBJ                             1  ~23     !4, 'hobbies'
         35        BOOL_NOT                                             ~24     ~23
         36      > JMPZ                                                         ~24, ->42
         37    >   FETCH_DIM_R                                          ~25     !4, 'hobbies'
         38        FRAMELESS_ICALL_2                implode             ~26     '%0A', ~25
         39        CONCAT                                               ~27     '%0AHobbies%3A+%0A', ~26
         40        QM_ASSIGN                                            ~28     ~27
         41      > JMP                                                          ->43
         42    >   QM_ASSIGN                                            ~28     ''
         43    >   ECHO                                                         ~28
   19    44      > JMP                                                          ->21
         45    >   FE_FREE                                                      $14
   27    46    > > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 6, Position 2 = 19
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 15
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
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: 19
filename:       /in/3vCFe
function name:  {closure:/in/3vCFe:7}
number of ops:  21
compiled vars:  !0 = $e, !1 = $search_string, !2 = $criteria
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    7     0  E >   RECV                                                 !0      
          1        BIND_STATIC                                                  !1
          2        BIND_STATIC                                                  !2
    9     3        ISSET_ISEMPTY_DIM_OBJ                             1  ~3      !0, !2
          4        BOOL_NOT                                             ~4      ~3
          5      > JMPZ_EX                                              ~4      ~4, ->19
   10     6    >   FETCH_DIM_R                                          ~5      !0, !2
          7        TYPE_CHECK                                      128  ~6      ~5
          8        BOOL_NOT                                             ~7      ~6
          9      > JMPZ                                                         ~7, ->15
   11    10    >   FETCH_DIM_R                                          ~8      !0, !2
         11        FRAMELESS_ICALL_2                strpos              ~9      ~8, !1
         12        TYPE_CHECK                                      1018  ~10     ~9
         13        QM_ASSIGN                                            ~11     ~10
         14      > JMP                                                          ->18
   12    15    >   FETCH_DIM_R                                          ~12     !0, !2
         16        FRAMELESS_ICALL_2                in_array            ~13     !1, ~12
         17        QM_ASSIGN                                            ~11     ~13
         18    >   BOOL                                                 ~4      ~11
         19    > > RETURN                                                       ~4
   15    20*     > RETURN                                                       null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
166.73 ms | 2284 KiB | 14 Q