3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = array ( "studentData" => array ( array( "university" => array( "name" => "Tes Name", "address" => "Street name", "province" => "Province name", ), "college" => array( "name" => "IT" ), "examDate" => "2019-01-20", "lesson" => array( "lessonId" => array( "lessonIdNumber" => "40" ) ), "countStudent" => "2", "examResult" => array( array( "studentGender" => "Male", "studentName" => array( array( "name" => "George", "result" => "98" ), array( "name" => "Leonard", "result" => "84" ), ), ) ) ), array( "university" => array( "name" => "Tes Name", "address" => "Street name", "province" => "Province name", ), "college" => array( "name" => "IT" ), "examDate" => "2019-01-20", "lesson" => array( "lessonId" => array( "lessonIdNumber" => "41" ) ), "countStudent" => "1", "examResult" => array( "studentGender" => "Female", "examDate" => "2019-01-20", "lessonId" => array( "lessonIdNumber" => "40" ), "countStudent" => "1", "studentName" => array( array( "name" => "Anita", "result" => "71" ) ), ) ), array( "university" => array( "name" => "Tes Name", "address" => "Street name", "province" => "Province name", ), "college" => array( "name" => "Design Graphics" ), "examDate" => "2019-01-20", "lesson" => array( "lessonId" => array( "lessonIdNumber" => "42" ) ), "countStudent" => "3", "examResult" => array( array( "studentGender" => "Male", "studentName" => array( array( "name" => "Edward", "result" => "83" ), array( "name" => "William", "result" => "86" ), array( "name" => "Oliver", "result" => "77" ), ), ) ) ), array( "university" => array( "name" => "Tes Name", "address" => "Street name", "province" => "Province name", ), "college" => array( "name" => "Design Graphics" ), "examDate" => "2019-01-20", "lesson" => array( "lessonId" => array( "lessonIdNumber" => "42" ) ), "countStudent" => "2", "examResult" => array( array( "studentGender" => "Female", "studentName" => array( array( "name" => "Isabel", "result" => "77" ), array( "name" => "Dorothi", "result" => "86" ) ), ), ) ), ), "lessonData" => array ( array( "lessonId" => array( "lessonIdNumber" => "40" ), "sessionName" => "PHP and Array", "teacherData" => array( "teacherName" => "Teacher Name One", "teacherId" => "229910", ), ), array( "lessonId" => array( "lessonIdNumber" => "41" ), "sessionName" => "Photoshop", "teacherData" => array( "teacherName" => "Teacher Name Two", "teacherId" => "981881", ), ), array( "lessonId" => array( "lessonIdNumber" => "42" ), "sessionName" => "Coreldraw", "teacherData" => array( "teacherName" => "Teacher Name Three", "teacherId" => "327718", ), ) ), ); $student = $data['studentData']; $lesson = $data['lessonData']; $expected = []; # mapping the lession id to lession data e.g 40=>[sessionName=>'Coreldraw','teacherData'=>[array]] foreach($lesson as $key=>$value){ $mapped[$value['lessonId']['lessonIdNumber']] = ['sessionName'=>$value['sessionName'],'teacherData'=>$value['teacherData']]; } foreach($student as $k=>$v){ $lesson_id = $v['lesson']['lessonId']['lessonIdNumber']; if(array_key_exists($lesson_id, $mapped)){ $expected['studentData'][$k] = array_merge($student[$k], $mapped[$lesson_id]); } } print_r($expected); ?>

Abusive script

This script was stopped while abusing our resources

Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 18
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 18
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 18
2 jumps found. (Code = 77) Position 1 = 20, Position 2 = 38
Branch analysis from position: 20
2 jumps found. (Code = 78) Position 1 = 21, Position 2 = 38
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 37
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 37
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
Branch analysis from position: 18
filename:       /in/9JW3J
function name:  (null)
number of ops:  43
compiled vars:  !0 = $data, !1 = $student, !2 = $lesson, !3 = $expected, !4 = $value, !5 = $key, !6 = $mapped, !7 = $v, !8 = $k, !9 = $lesson_id
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
  190     1        FETCH_DIM_R                                      ~11     !0, 'studentData'
          2        ASSIGN                                                   !1, ~11
  191     3        FETCH_DIM_R                                      ~13     !0, 'lessonData'
          4        ASSIGN                                                   !2, ~13
  192     5        ASSIGN                                                   !3, <array>
  194     6      > FE_RESET_R                                       $16     !2, ->18
          7    > > FE_FETCH_R                                       ~17     $16, !4, ->18
          8    >   ASSIGN                                                   !5, ~17
  195     9        FETCH_DIM_R                                      ~19     !4, 'lessonId'
         10        FETCH_DIM_R                                      ~20     ~19, 'lessonIdNumber'
         11        FETCH_DIM_R                                      ~22     !4, 'sessionName'
         12        INIT_ARRAY                                       ~23     ~22, 'sessionName'
         13        FETCH_DIM_R                                      ~24     !4, 'teacherData'
         14        ADD_ARRAY_ELEMENT                                ~23     ~24, 'teacherData'
         15        ASSIGN_DIM                                               !6, ~20
         16        OP_DATA                                                  ~23
  194    17      > JMP                                                      ->7
         18    >   FE_FREE                                                  $16
  198    19      > FE_RESET_R                                       $25     !1, ->38
         20    > > FE_FETCH_R                                       ~26     $25, !7, ->38
         21    >   ASSIGN                                                   !8, ~26
  199    22        FETCH_DIM_R                                      ~28     !7, 'lesson'
         23        FETCH_DIM_R                                      ~29     ~28, 'lessonId'
         24        FETCH_DIM_R                                      ~30     ~29, 'lessonIdNumber'
         25        ASSIGN                                                   !9, ~30
  200    26        ARRAY_KEY_EXISTS                                         !9, !6
         27      > JMPZ                                                     ~32, ->37
  201    28    >   INIT_FCALL                                               'array_merge'
         29        FETCH_DIM_R                                      ~35     !1, !8
         30        SEND_VAL                                                 ~35
         31        FETCH_DIM_R                                      ~36     !6, !9
         32        SEND_VAL                                                 ~36
         33        DO_ICALL                                         $37     
         34        FETCH_DIM_W                                      $33     !3, 'studentData'
         35        ASSIGN_DIM                                               $33, !8
         36        OP_DATA                                                  $37
  198    37    > > JMP                                                      ->20
         38    >   FE_FREE                                                  $25
  205    39        INIT_FCALL                                               'print_r'
         40        SEND_VAR                                                 !3
         41        DO_ICALL                                                 
  206    42      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.15 ms | 1022 KiB | 15 Q