3v4l.org

run code in 300+ PHP versions simultaneously
<?php $keywords = ['Paso', 'Robles']; $columns = ['ID', 'StorageArea', 'Size', 'Winery', 'Brand', 'Appellation', 'ReleaseYear', 'Varietal', 'Status', 'CountryName']; $where = 'WHERE ' . implode("\nAND ", array_map(function ($keyword) use ($columns) { $keyword = str_replace("'", "''", $keyword); return "\n(" . implode(' OR ', array_map(function ($column) use ($keyword) { return "\n`$column` LIKE '%$keyword%'"; }, array_filter($columns, function ($column) { return $column !== 'ID'; }))) . "\n)"; }, $keywords)); echo $where;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GqEXQ
function name:  (null)
number of ops:  16
compiled vars:  !0 = $keywords, !1 = $columns, !2 = $where
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1        ASSIGN                                                   !1, <array>
    6     2        INIT_FCALL                                               'implode'
          3        SEND_VAL                                                 '%0AAND+'
          4        INIT_FCALL                                               'array_map'
          5        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FGqEXQ%3A6%240'
          6        BIND_LEXICAL                                             ~5, !1
   14     7        SEND_VAL                                                 ~5
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $6      
         10        SEND_VAR                                                 $6
         11        DO_ICALL                                         $7      
         12        CONCAT                                           ~8      'WHERE+', $7
    6    13        ASSIGN                                                   !2, ~8
   16    14        ECHO                                                     !2
   17    15      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FGqEXQ%3A6%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GqEXQ
function name:  {closure}
number of ops:  27
compiled vars:  !0 = $keyword, !1 = $columns
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
    7     2        INIT_FCALL                                               'str_replace'
          3        SEND_VAL                                                 '%27'
          4        SEND_VAL                                                 '%27%27'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $2      
          7        ASSIGN                                                   !0, $2
    9     8        INIT_FCALL                                               'implode'
          9        SEND_VAL                                                 '+OR+'
         10        INIT_FCALL                                               'array_map'
         11        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FGqEXQ%3A9%241'
         12        BIND_LEXICAL                                             ~4, !0
   11    13        SEND_VAL                                                 ~4
         14        INIT_FCALL                                               'array_filter'
         15        SEND_VAR                                                 !1
         16        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FGqEXQ%3A11%242'
   13    17        SEND_VAL                                                 ~5
         18        DO_ICALL                                         $6      
         19        SEND_VAR                                                 $6
         20        DO_ICALL                                         $7      
         21        SEND_VAR                                                 $7
         22        DO_ICALL                                         $8      
         23        CONCAT                                           ~9      '%0A%28', $8
         24        CONCAT                                           ~10     ~9, '%0A%29'
         25      > RETURN                                                   ~10
   14    26*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FGqEXQ%3A6%240

Function %00%7Bclosure%7D%2Fin%2FGqEXQ%3A9%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GqEXQ
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $column, !1 = $keyword
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   10     2        ROPE_INIT                                     5  ~3      '%0A%60'
          3        ROPE_ADD                                      1  ~3      ~3, !0
          4        ROPE_ADD                                      2  ~3      ~3, '%60+LIKE+%27%25'
          5        ROPE_ADD                                      3  ~3      ~3, !1
          6        ROPE_END                                      4  ~2      ~3, '%25%27'
          7      > RETURN                                                   ~2
   11     8*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FGqEXQ%3A9%241

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

End of function %00%7Bclosure%7D%2Fin%2FGqEXQ%3A11%242

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.45 ms | 1411 KiB | 21 Q