3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Write a function that accepts an array of strings and return another array * with strings in the input array set as keys. * * @param string[] $arrOfStrings An array of strings. * @return array Another array with strings in the input array set as keys. */ function foo(array $arrOfStrings) { return array_fill_keys(array_filter($arrOfStrings, 'is_string'), null); } /** * Now write another function that accepts the output of the previous function, * as first argument and another string as second argument. In this function, * assume that you have some reason to iterate over the the input array using * foreach, key => value format. In every iteration, in addition to other stuff, * you also have to check if the key is equal to the input string (the second * parameter of this function), and if they match do some stuff.... * * @param array $outputFromFoo The output from {@link foo()}. */ function bar(array $outputFromFoo, string $str) { foreach ($outputFromFoo as $key => $value) { // other stuff if ($key === $str) { echo "Found $str!"; } } } $result = foo(array('ab', 'cd', '10')); bar($result, '10');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Fm0dQ
function name:  (null)
number of ops:  9
compiled vars:  !0 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   INIT_FCALL                                               'foo'
          1        SEND_VAL                                                 <array>
          2        DO_FCALL                                      0  $1      
          3        ASSIGN                                                   !0, $1
   37     4        INIT_FCALL                                               'bar'
          5        SEND_VAR                                                 !0
          6        SEND_VAL                                                 '10'
          7        DO_FCALL                                      0          
          8      > RETURN                                                   1

Function foo:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Fm0dQ
function name:  foo
number of ops:  11
compiled vars:  !0 = $arrOfStrings
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
   12     1        INIT_FCALL                                               'array_fill_keys'
          2        INIT_FCALL                                               'array_filter'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 'is_string'
          5        DO_ICALL                                         $1      
          6        SEND_VAR                                                 $1
          7        SEND_VAL                                                 null
          8        DO_ICALL                                         $2      
          9      > RETURN                                                   $2
   13    10*     > RETURN                                                   null

End of function foo

Function bar:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 12
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 12
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 11
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 11
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/Fm0dQ
function name:  bar
number of ops:  14
compiled vars:  !0 = $outputFromFoo, !1 = $str, !2 = $value, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   27     2      > FE_RESET_R                                       $4      !0, ->12
          3    > > FE_FETCH_R                                       ~5      $4, !2, ->12
          4    >   ASSIGN                                                   !3, ~5
   30     5        IS_IDENTICAL                                             !3, !1
          6      > JMPZ                                                     ~7, ->11
   31     7    >   ROPE_INIT                                     3  ~9      'Found+'
          8        ROPE_ADD                                      1  ~9      ~9, !1
          9        ROPE_END                                      2  ~8      ~9, '%21'
         10        ECHO                                                     ~8
   27    11    > > JMP                                                      ->3
         12    >   FE_FREE                                                  $4
   34    13      > RETURN                                                   null

End of function bar

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.3 ms | 1394 KiB | 19 Q