3v4l.org

run code in 300+ PHP versions simultaneously
<?php $username = 'test'; $translateWord = 'How are you'; $words = explode(' ', $translateWord); $list = implode(',', array_map(function ($word) { return "'" . strtolower(trim($word)) . "'"; }, $words)); $query = "SELECT LOWER(English) AS English, LOWER(Translation) AS Translation FROM $username WHERE LOWER(English) IN ($list)"; // query table // $result = $connection->query($query); // $rows = $result->fetch_all(); // simulated result $rows = array(array('English' => 'how', 'Translation' => 'como'), array('English' => 'are', 'Translation' => 'son'), array('English' => 'you', 'Translation' => 'tu')); $translation = array(); foreach ($words as $word) { if (($key = array_search(strtolower($word), array_column($rows, 'English'))) !== false) { // match case of result if (strtoupper($word) == $word) { $translation[] = strtoupper($rows[$key]['Translation']); } elseif (ucfirst($word) == $word) { $translation[] = ucfirst($rows[$key]['Translation']); } else { $translation[] = $rows[$key]['Translation']; } } else { // no match, leave alone $translation[] = $word; } } echo $translateWord . " => " . implode(' ', $translation);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 26, Position 2 = 75
Branch analysis from position: 26
2 jumps found. (Code = 78) Position 1 = 27, Position 2 = 75
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 72
Branch analysis from position: 41
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 54
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 71
Branch analysis from position: 71
1 jumps found. (Code = 42) Position 1 = 74
Branch analysis from position: 74
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 54
2 jumps found. (Code = 43) Position 1 = 59, Position 2 = 67
Branch analysis from position: 59
1 jumps found. (Code = 42) Position 1 = 71
Branch analysis from position: 71
Branch analysis from position: 67
1 jumps found. (Code = 42) Position 1 = 74
Branch analysis from position: 74
Branch analysis from position: 72
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 75
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 75
filename:       /in/JsDFE
function name:  (null)
number of ops:  84
compiled vars:  !0 = $username, !1 = $translateWord, !2 = $words, !3 = $list, !4 = $query, !5 = $rows, !6 = $translation, !7 = $word, !8 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'test'
    4     1        ASSIGN                                                   !1, 'How+are+you'
    5     2        INIT_FCALL                                               'explode'
          3        SEND_VAL                                                 '+'
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $11     
          6        ASSIGN                                                   !2, $11
    6     7        INIT_FCALL                                               'implode'
          8        SEND_VAL                                                 '%2C'
          9        INIT_FCALL                                               'array_map'
         10        DECLARE_LAMBDA_FUNCTION                          ~13     [0]
         11        SEND_VAL                                                 ~13
         12        SEND_VAR                                                 !2
         13        DO_ICALL                                         $14     
         14        SEND_VAR                                                 $14
         15        DO_ICALL                                         $15     
         16        ASSIGN                                                   !3, $15
    7    17        ROPE_INIT                                     5  ~18     'SELECT+LOWER%28English%29+AS+English%2C+LOWER%28Translation%29+AS+Translation%0A++++++++++FROM+'
    8    18        ROPE_ADD                                      1  ~18     ~18, !0
         19        ROPE_ADD                                      2  ~18     ~18, '%0A++++++++++WHERE+LOWER%28English%29+IN+%28'
    9    20        ROPE_ADD                                      3  ~18     ~18, !3
         21        ROPE_END                                      4  ~17     ~18, '%29'
    7    22        ASSIGN                                                   !4, ~17
   14    23        ASSIGN                                                   !5, <array>
   17    24        ASSIGN                                                   !6, <array>
   18    25      > FE_RESET_R                                       $24     !2, ->75
         26    > > FE_FETCH_R                                               $24, !7, ->75
   19    27    >   INIT_FCALL                                               'array_search'
         28        INIT_FCALL                                               'strtolower'
         29        SEND_VAR                                                 !7
         30        DO_ICALL                                         $25     
         31        SEND_VAR                                                 $25
         32        INIT_FCALL                                               'array_column'
         33        SEND_VAR                                                 !5
         34        SEND_VAL                                                 'English'
         35        DO_ICALL                                         $26     
         36        SEND_VAR                                                 $26
         37        DO_ICALL                                         $27     
         38        ASSIGN                                           ~28     !8, $27
         39        TYPE_CHECK                                  1018          ~28
         40      > JMPZ                                                     ~29, ->72
   21    41    >   INIT_FCALL                                               'strtoupper'
         42        SEND_VAR                                                 !7
         43        DO_ICALL                                         $30     
         44        IS_EQUAL                                                 !7, $30
         45      > JMPZ                                                     ~31, ->54
   22    46    >   INIT_FCALL                                               'strtoupper'
         47        FETCH_DIM_R                                      ~33     !5, !8
         48        FETCH_DIM_R                                      ~34     ~33, 'Translation'
         49        SEND_VAL                                                 ~34
         50        DO_ICALL                                         $35     
         51        ASSIGN_DIM                                               !6
         52        OP_DATA                                                  $35
   21    53      > JMP                                                      ->71
   24    54    >   INIT_FCALL                                               'ucfirst'
         55        SEND_VAR                                                 !7
         56        DO_ICALL                                         $36     
         57        IS_EQUAL                                                 !7, $36
         58      > JMPZ                                                     ~37, ->67
   25    59    >   INIT_FCALL                                               'ucfirst'
         60        FETCH_DIM_R                                      ~39     !5, !8
         61        FETCH_DIM_R                                      ~40     ~39, 'Translation'
         62        SEND_VAL                                                 ~40
         63        DO_ICALL                                         $41     
         64        ASSIGN_DIM                                               !6
         65        OP_DATA                                                  $41
   24    66      > JMP                                                      ->71
   28    67    >   FETCH_DIM_R                                      ~43     !5, !8
         68        FETCH_DIM_R                                      ~44     ~43, 'Translation'
         69        ASSIGN_DIM                                               !6
         70        OP_DATA                                                  ~44
   19    71    > > JMP                                                      ->74
   33    72    >   ASSIGN_DIM                                               !6
         73        OP_DATA                                                  !7
   18    74    > > JMP                                                      ->26
         75    >   FE_FREE                                                  $24
   36    76        CONCAT                                           ~46     !1, '+%3D%3E+'
         77        INIT_FCALL                                               'implode'
         78        SEND_VAL                                                 '+'
         79        SEND_VAR                                                 !6
         80        DO_ICALL                                         $47     
         81        CONCAT                                           ~48     ~46, $47
         82        ECHO                                                     ~48
         83      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JsDFE
function name:  {closure}
number of ops:  11
compiled vars:  !0 = $word
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        INIT_FCALL                                               'strtolower'
          2        INIT_FCALL                                               'trim'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $1      
          5        SEND_VAR                                                 $1
          6        DO_ICALL                                         $2      
          7        CONCAT                                           ~3      '%27', $2
          8        CONCAT                                           ~4      ~3, '%27'
          9      > RETURN                                                   ~4
         10*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.36 ms | 1016 KiB | 22 Q