3v4l.org

run code in 300+ PHP versions simultaneously
<?php $user = (object) [ 'roles' => [ 'student', //remove 'grade_1_student', 'grade_4_student', 'grade_some_student', //remove 'arbitrarty-0', //remove 'grade_9_student', ], ]; function getStudentGradesFromRoles(array $roles) { static $grades = [ 'grade_1_student' => 'grade-1', 'grade_2_student' => 'grade-2', 'grade_3_student' => 'grade-3', 'grade_4_student' => 'grade-4', 'grade_5_student' => 'grade-5', 'grade_6_student' => 'grade-6', 'grade_7_student' => 'grade-7', 'grade_8_student' => 'grade-8', 'grade_9_student' => 'grade-9', ]; return array_values(array_intersect_key($grades, array_flip($roles))); } $grades = getStudentGradesFromRoles((array) $user->roles); var_dump($grades);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IODVN
function name:  (null)
number of ops:  12
compiled vars:  !0 = $user, !1 = $grades
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   CAST                                          8  ~2      <array>
    4     1        ASSIGN                                                   !0, ~2
   31     2        INIT_FCALL                                               'getstudentgradesfromroles'
          3        FETCH_OBJ_R                                      ~4      !0, 'roles'
          4        CAST                                          7  ~5      ~4
          5        SEND_VAL                                                 ~5
          6        DO_FCALL                                      0  $6      
          7        ASSIGN                                                   !1, $6
   32     8        INIT_FCALL                                               'var_dump'
          9        SEND_VAR                                                 !1
         10        DO_ICALL                                                 
         11      > RETURN                                                   1

Function getstudentgradesfromroles:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IODVN
function name:  getStudentGradesFromRoles
number of ops:  14
compiled vars:  !0 = $roles, !1 = $grades
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   16     1        BIND_STATIC                                              !1
   28     2        INIT_FCALL                                               'array_values'
          3        INIT_FCALL                                               'array_intersect_key'
          4        SEND_VAR                                                 !1
          5        INIT_FCALL                                               'array_flip'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $2      
          8        SEND_VAR                                                 $2
          9        DO_ICALL                                         $3      
         10        SEND_VAR                                                 $3
         11        DO_ICALL                                         $4      
         12      > RETURN                                                   $4
   29    13*     > RETURN                                                   null

End of function getstudentgradesfromroles

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.89 ms | 1003 KiB | 18 Q