3v4l.org

run code in 500+ PHP versions simultaneously
<?php $data = [ 'Newcastle Upon Tyne, Tyne and Wear, England' => 18, 'Gateshead, Tyne and Wear, England' => 17, 'Sunderland, Tyne and Wear, England' => 3, ]; $result = []; /*foreach($data as $key=>$value){ $result[explode(',',$key)[0]] = $value; }*/ array_walk($data, function (&$value,$key) use (&$result) { $splitted = explode(",",$key); $result[ $splitted[0] ] = $value; }); print_r($result);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YWYLY
function name:  (null)
number of ops:  12
compiled vars:  !0 = $data, !1 = $result
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
    9     1        ASSIGN                                                       !1, <array>
   14     2        INIT_FCALL                                                   'array_walk'
          3        SEND_REF                                                     !0
          4        DECLARE_LAMBDA_FUNCTION                              ~4      [0]
          5        BIND_LEXICAL                                                 ~4, !1
   17     6        SEND_VAL                                                     ~4
   14     7        DO_ICALL                                                     
   19     8        INIT_FCALL                                                   'print_r'
          9        SEND_VAR                                                     !1
         10        DO_ICALL                                                     
         11      > 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/YWYLY
function name:  {closure:/in/YWYLY:14}
number of ops:  12
compiled vars:  !0 = $value, !1 = $key, !2 = $result, !3 = $splitted
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   14     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        BIND_STATIC                                                  !2
   15     3        INIT_FCALL                                                   'explode'
          4        SEND_VAL                                                     '%2C'
          5        SEND_VAR                                                     !1
          6        DO_ICALL                                             $4      
          7        ASSIGN                                                       !3, $4
   16     8        FETCH_DIM_R                                          ~6      !3, 0
          9        ASSIGN_DIM                                                   !2, ~6
         10        OP_DATA                                                      !0
   17    11      > RETURN                                                       null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
160.45 ms | 2550 KiB | 16 Q