3v4l.org

run code in 300+ 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 = 49
Branch analysis from position: 14
2 jumps found. (Code = 77) Position 1 = 21, Position 2 = 48
Branch analysis from position: 21
2 jumps found. (Code = 78) Position 1 = 22, Position 2 = 48
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 45
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 48
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 48
Branch analysis from position: 49
filename:       /in/3vCFe
function name:  (null)
number of ops:  50
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                                  '%00%7Bclosure%7D%2Fin%2F3vCFe%3A7%240'
          6        BIND_LEXICAL                                             ~8, !1
          7        BIND_LEXICAL                                             ~8, !2
   15     8        SEND_VAL                                                 ~8
          9        DO_ICALL                                         $9      
    7    10        ASSIGN                                                   !3, $9
   17    11        ISSET_ISEMPTY_CV                                 ~11     !3
         12        BOOL_NOT                                         ~12     ~11
         13      > JMPZ                                                     ~12, ->49
   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, ->48
         21    > > FE_FETCH_R                                               $14, !4, ->48
   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, ->45
         37    >   INIT_FCALL                                               'implode'
         38        SEND_VAL                                                 '%0A'
         39        FETCH_DIM_R                                      ~25     !4, 'hobbies'
         40        SEND_VAL                                                 ~25
         41        DO_ICALL                                         $26     
         42        CONCAT                                           ~27     '%0AHobbies%3A+%0A', $26
         43        QM_ASSIGN                                        ~28     ~27
         44      > JMP                                                      ->46
         45    >   QM_ASSIGN                                        ~28     ''
         46    >   ECHO                                                     ~28
   19    47      > JMP                                                      ->21
         48    >   FE_FREE                                                  $14
   27    49    > > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2F3vCFe%3A7%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 6, Position 2 = 25
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 18
Branch analysis from position: 10
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: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/3vCFe
function name:  {closure}
number of ops:  27
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, ->25
   10     6    >   FETCH_DIM_R                                      ~5      !0, !2
          7        TYPE_CHECK                                  128  ~6      ~5
          8        BOOL_NOT                                         ~7      ~6
          9      > JMPZ                                                     ~7, ->18
   11    10    >   INIT_FCALL                                               'strpos'
         11        FETCH_DIM_R                                      ~8      !0, !2
         12        SEND_VAL                                                 ~8
         13        SEND_VAR                                                 !1
         14        DO_ICALL                                         $9      
         15        TYPE_CHECK                                  1018  ~10     $9
         16        QM_ASSIGN                                        ~11     ~10
         17      > JMP                                                      ->24
   12    18    >   INIT_FCALL                                               'in_array'
         19        SEND_VAR                                                 !1
         20        FETCH_DIM_R                                      ~12     !0, !2
         21        SEND_VAL                                                 ~12
         22        DO_ICALL                                         $13     
         23        QM_ASSIGN                                        ~11     $13
         24    >   BOOL                                             ~4      ~11
         25    > > RETURN                                                   ~4
   15    26*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F3vCFe%3A7%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
174.63 ms | 1404 KiB | 21 Q