3v4l.org

run code in 300+ PHP versions simultaneously
<?php $carts = array( 'Olivia' => array(51, 3, 2), 'Harry' => array(312, 314, 10), 'Charlie' => array(1, 314, 626) ); $fruits = array( 'Apple' => array('id' => 1), 'Banana' => array('id' => 2), 'Peach' => array('id' => 3) ); $fru = array_map(function($item){return $item['id'];}, $fruits); foreach ($carts as $cart) { $find = array_intersect($cart, $fru); if (count($find)){ $result = implode(", ", array_map(function($item) use($fru){ return array_search($item, $fru); }, $find)); echo "Fruit ({$result})\n"; } else echo "No Fruit \n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 35
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 35
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 33
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
filename:       /in/hpGEX
function name:  (null)
number of ops:  37
compiled vars:  !0 = $carts, !1 = $fruits, !2 = $fru, !3 = $cart, !4 = $find, !5 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    7     1        ASSIGN                                                   !1, <array>
   13     2        INIT_FCALL                                               'array_map'
          3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FhpGEX%3A13%240'
          4        SEND_VAL                                                 ~8
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $9      
          7        ASSIGN                                                   !2, $9
   14     8      > FE_RESET_R                                       $11     !0, ->35
          9    > > FE_FETCH_R                                               $11, !3, ->35
   15    10    >   INIT_FCALL                                               'array_intersect'
         11        SEND_VAR                                                 !3
         12        SEND_VAR                                                 !2
         13        DO_ICALL                                         $12     
         14        ASSIGN                                                   !4, $12
   16    15        COUNT                                            ~14     !4
         16      > JMPZ                                                     ~14, ->33
   17    17    >   INIT_FCALL                                               'implode'
         18        SEND_VAL                                                 '%2C+'
         19        INIT_FCALL                                               'array_map'
         20        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FhpGEX%3A17%241'
         21        BIND_LEXICAL                                             ~15, !2
   19    22        SEND_VAL                                                 ~15
         23        SEND_VAR                                                 !4
         24        DO_ICALL                                         $16     
         25        SEND_VAR                                                 $16
         26        DO_ICALL                                         $17     
   17    27        ASSIGN                                                   !5, $17
   20    28        ROPE_INIT                                     3  ~20     'Fruit+%28'
         29        ROPE_ADD                                      1  ~20     ~20, !5
         30        ROPE_END                                      2  ~19     ~20, '%29%0A'
         31        ECHO                                                     ~19
         32      > JMP                                                      ->34
   22    33    >   ECHO                                                     'No+Fruit+%0A'
   14    34    > > JMP                                                      ->9
         35    >   FE_FREE                                                  $11
   23    36      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FhpGEX%3A13%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hpGEX
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        FETCH_DIM_R                                      ~1      !0, 'id'
          2      > RETURN                                                   ~1
          3*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FhpGEX%3A13%240

Function %00%7Bclosure%7D%2Fin%2FhpGEX%3A17%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hpGEX
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $item, !1 = $fru
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   18     2        INIT_FCALL                                               'array_search'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $2      
          6      > RETURN                                                   $2
   19     7*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FhpGEX%3A17%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.49 ms | 1405 KiB | 21 Q