3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ 0 => [ "user_type" => 'Manager', "total_count" => 3, ], 1 => [ "user_type" => 'Director', "total_count" => 2, ] ]; $array_column = array_column($array, 'total_count', 'user_type'); //Create new array like below $add_array = array('Manager'=>'0', 'Director'=>'0', 'Trainee'=>'0',); //using array_merge merge add_array and array_column $new_array = array_merge($add_array, $array_column); //using array_walk_recursive get the requird result array_walk_recursive($new_array, function($item, $key) use (&$final_array){ $final_array['labels'][]=$key; $final_array['dataset'][]=$item; }); echo "<pre>"; print_r($final_array); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tNPfU
function name:  (null)
number of ops:  24
compiled vars:  !0 = $array, !1 = $array_column, !2 = $add_array, !3 = $new_array, !4 = $final_array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   ASSIGN                                                   !0, <array>
   25     1        INIT_FCALL                                               'array_column'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 'total_count'
          4        SEND_VAL                                                 'user_type'
          5        DO_ICALL                                         $6      
          6        ASSIGN                                                   !1, $6
   28     7        ASSIGN                                                   !2, <array>
   31     8        INIT_FCALL                                               'array_merge'
          9        SEND_VAR                                                 !2
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                         $9      
         12        ASSIGN                                                   !3, $9
   35    13        INIT_FCALL                                               'array_walk_recursive'
         14        SEND_REF                                                 !3
         15        DECLARE_LAMBDA_FUNCTION                          ~11     [0]
         16        BIND_LEXICAL                                             ~11, !4
   39    17        SEND_VAL                                                 ~11
   35    18        DO_ICALL                                                 
   41    19        ECHO                                                     '%3Cpre%3E'
   42    20        INIT_FCALL                                               'print_r'
         21        SEND_VAR                                                 !4
         22        DO_ICALL                                                 
   44    23      > 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/tNPfU
function name:  {closure}
number of ops:  10
compiled vars:  !0 = $item, !1 = $key, !2 = $final_array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
   37     3        FETCH_DIM_W                                      $3      !2, 'labels'
          4        ASSIGN_DIM                                               $3
          5        OP_DATA                                                  !1
   38     6        FETCH_DIM_W                                      $5      !2, 'dataset'
          7        ASSIGN_DIM                                               $5
          8        OP_DATA                                                  !0
   39     9      > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.74 ms | 1002 KiB | 17 Q