3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Teacher { public function getStudentTeacherColumn(array $data, int|string $col): array { return array_map([$this, 'myarraymap'], $data['student_teacher']); } private function myarraymap(array $studentTeacher): mixed { return $studentTeacher['user_id']; // statically accessing column to demonstrate desired output } } $data = [ 'student_teacher' => [ ['user_id' => 1, 'user_name' => 'foo'], ['user_id' => 2, 'user_name' => 'bar'], ['user_id' => 3, 'user_name' => 'bam'], ] ]; $teacher = new Teacher; var_export($teacher->getStudentTeacherColumn($data, 'user_id')); echo "\n---\n"; $col = 'user_id'; var_export(array_column($data['student_teacher'], $col));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZQXPo
function name:  (null)
number of ops:  22
compiled vars:  !0 = $data, !1 = $teacher, !2 = $col
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   ASSIGN                                                   !0, <array>
   24     1        NEW                                              $4      'Teacher'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $4
   25     4        INIT_FCALL                                               'var_export'
          5        INIT_METHOD_CALL                                         !1, 'getStudentTeacherColumn'
          6        SEND_VAR_EX                                              !0
          7        SEND_VAL_EX                                              'user_id'
          8        DO_FCALL                                      0  $7      
          9        SEND_VAR                                                 $7
         10        DO_ICALL                                                 
   26    11        ECHO                                                     '%0A---%0A'
   27    12        ASSIGN                                                   !2, 'user_id'
   28    13        INIT_FCALL                                               'var_export'
         14        INIT_FCALL                                               'array_column'
         15        FETCH_DIM_R                                      ~10     !0, 'student_teacher'
         16        SEND_VAL                                                 ~10
         17        SEND_VAR                                                 !2
         18        DO_ICALL                                         $11     
         19        SEND_VAR                                                 $11
         20        DO_ICALL                                                 
         21      > RETURN                                                   1

Class Teacher:
Function getstudentteachercolumn:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZQXPo
function name:  getStudentTeacherColumn
number of ops:  14
compiled vars:  !0 = $data, !1 = $col
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    7     2        INIT_FCALL                                               'array_map'
          3        FETCH_THIS                                       ~2      
          4        INIT_ARRAY                                       ~3      ~2
          5        ADD_ARRAY_ELEMENT                                ~3      'myarraymap'
          6        SEND_VAL                                                 ~3
          7        FETCH_DIM_R                                      ~4      !0, 'student_teacher'
          8        SEND_VAL                                                 ~4
          9        DO_ICALL                                         $5      
         10        VERIFY_RETURN_TYPE                                       $5
         11      > RETURN                                                   $5
    8    12*       VERIFY_RETURN_TYPE                                       
         13*     > RETURN                                                   null

End of function getstudentteachercolumn

Function myarraymap:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZQXPo
function name:  myarraymap
number of ops:  5
compiled vars:  !0 = $studentTeacher
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
   12     1        FETCH_DIM_R                                      ~1      !0, 'user_id'
          2      > RETURN                                                   ~1
   13     3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function myarraymap

End of class Teacher.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.62 ms | 1007 KiB | 16 Q