3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = array( "abc"=>array( "label" => "abc", "value" => "def", "type" => "ghi", "desc" => "jkl", ), "def"=>array( "label" => "mno", "value" => "qrs", "type" => "tuv", "desc" => "wxyz", ), ); $matches = array(); $pattern = "/a/i"; //contains an 'a' //loop through the data foreach($data as $key=>$value){ //loop through each key under data sub array foreach($value as $key2=>$value2){ //check for match. if(preg_match($pattern, $value2)){ //add to matches array. $matches[$key]=$value; //match found, so break from foreach break; } } } echo '<pre>'.print_r($matches, true).'</pre>';
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 20
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 20
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 18
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 18
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 17
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 18
Branch analysis from position: 18
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
filename:       /in/W2ZHS
function name:  (null)
number of ops:  29
compiled vars:  !0 = $data, !1 = $matches, !2 = $pattern, !3 = $value, !4 = $key, !5 = $value2, !6 = $key2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   17     1        ASSIGN                                                   !1, <array>
   18     2        ASSIGN                                                   !2, '%2Fa%2Fi'
   20     3      > FE_RESET_R                                       $10     !0, ->20
          4    > > FE_FETCH_R                                       ~11     $10, !3, ->20
          5    >   ASSIGN                                                   !4, ~11
   22     6      > FE_RESET_R                                       $13     !3, ->18
          7    > > FE_FETCH_R                                       ~14     $13, !5, ->18
          8    >   ASSIGN                                                   !6, ~14
   24     9        INIT_FCALL                                               'preg_match'
         10        SEND_VAR                                                 !2
         11        SEND_VAR                                                 !5
         12        DO_ICALL                                         $16     
         13      > JMPZ                                                     $16, ->17
   26    14    >   ASSIGN_DIM                                               !1, !4
         15        OP_DATA                                                  !3
   28    16      > JMP                                                      ->18
   22    17    > > JMP                                                      ->7
         18    >   FE_FREE                                                  $13
   20    19      > JMP                                                      ->4
         20    >   FE_FREE                                                  $10
   32    21        INIT_FCALL                                               'print_r'
         22        SEND_VAR                                                 !1
         23        SEND_VAL                                                 <true>
         24        DO_ICALL                                         $18     
         25        CONCAT                                           ~19     '%3Cpre%3E', $18
         26        CONCAT                                           ~20     ~19, '%3C%2Fpre%3E'
         27        ECHO                                                     ~20
         28      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.81 ms | 1396 KiB | 17 Q