3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json = '[ {"title":"The Call of the Wild","author":"Jack London"}, {"title":"Great Expectations","author":"Charles Dickens"}, {"title":"The Voyage of the Beatle","author":"Charles Darwin"} ]'; $array = json_decode($json, true); function searchArrayKeyVal($search, $array) { $results = array(); // search for string in each column foreach ($array as $idx => $obj) { foreach ($obj as $key => $value) { if (stripos($value, $search) !== false) { array_push($results, $obj); break; } } } return $results; } print_r(searchArrayKeyVal('charles', $array)); print_r(searchArrayKeyVal('wild', $array));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NiWFj
function name:  (null)
number of ops:  21
compiled vars:  !0 = $json, !1 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, '%5B%0A++++%7B%22title%22%3A%22The+Call+of+the+Wild%22%2C%22author%22%3A%22Jack+London%22%7D%2C%0A++++%7B%22title%22%3A%22Great+Expectations%22%2C%22author%22%3A%22Charles+Dickens%22%7D%2C%0A++++%7B%22title%22%3A%22The+Voyage+of+the+Beatle%22%2C%22author%22%3A%22Charles+Darwin%22%7D%0A%5D'
   10     1        INIT_FCALL                                               'json_decode'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 <true>
          4        DO_ICALL                                         $3      
          5        ASSIGN                                                   !1, $3
   26     6        INIT_FCALL                                               'print_r'
          7        INIT_FCALL                                               'searcharraykeyval'
          8        SEND_VAL                                                 'charles'
          9        SEND_VAR                                                 !1
         10        DO_FCALL                                      0  $5      
         11        SEND_VAR                                                 $5
         12        DO_ICALL                                                 
   27    13        INIT_FCALL                                               'print_r'
         14        INIT_FCALL                                               'searcharraykeyval'
         15        SEND_VAL                                                 'wild'
         16        SEND_VAR                                                 !1
         17        DO_FCALL                                      0  $7      
         18        SEND_VAR                                                 $7
         19        DO_ICALL                                                 
         20      > RETURN                                                   1

Function searcharraykeyval:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 23
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 23
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 21
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 21
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 20
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 21
Branch analysis from position: 21
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
filename:       /in/NiWFj
function name:  searchArrayKeyVal
number of ops:  26
compiled vars:  !0 = $search, !1 = $array, !2 = $results, !3 = $obj, !4 = $idx, !5 = $value, !6 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   13     2        ASSIGN                                                   !2, <array>
   15     3      > FE_RESET_R                                       $8      !1, ->23
          4    > > FE_FETCH_R                                       ~9      $8, !3, ->23
          5    >   ASSIGN                                                   !4, ~9
   16     6      > FE_RESET_R                                       $11     !3, ->21
          7    > > FE_FETCH_R                                       ~12     $11, !5, ->21
          8    >   ASSIGN                                                   !6, ~12
   17     9        INIT_FCALL                                               'stripos'
         10        SEND_VAR                                                 !5
         11        SEND_VAR                                                 !0
         12        DO_ICALL                                         $14     
         13        TYPE_CHECK                                  1018          $14
         14      > JMPZ                                                     ~15, ->20
   18    15    >   INIT_FCALL                                               'array_push'
         16        SEND_REF                                                 !2
         17        SEND_VAR                                                 !3
         18        DO_ICALL                                                 
   19    19      > JMP                                                      ->21
   16    20    > > JMP                                                      ->7
         21    >   FE_FREE                                                  $11
   15    22      > JMP                                                      ->4
         23    >   FE_FREE                                                  $8
   23    24      > RETURN                                                   !2
   24    25*     > RETURN                                                   null

End of function searcharraykeyval

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
128.16 ms | 1407 KiB | 23 Q