title: How to insert second array value into first array with php
body: <p>I have multidimensional array given from thirth party supplier with detail as bellow.</p>
  
  <pre>$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",
              ),
          )
      ),
  );
  </pre>
  
  <p>Data output : <a href="https://3v4l.org/uUGsB" rel="nofollow noreferrer">https://3v4l.org/uUGsB</a></p>
  
  <p>I have to modify result from above array base on every "lessonIdNumber" from "lessonData" tag with scenario : move value of [sessionName] and [teacherData] from [lessonData] into bellow each [lesson] in [studentData] array base on each [lessonIdNumber].</p>
  
  <p><pre>
  Array
  (
      [studentData] => Array
          (
              [0] => Array
                  (
                      [university] => Array
                          (
                              [name] => Tes Name
                              [address] => Street name
                              [province] => Province name
                          )</p>
  
  <code>                [college] =&gt; Array
                      (
                          [name] =&gt; IT
                      )
  
                  [examDate] =&gt; 2019-01-20
                  [lesson] =&gt; Array
                      (
                          [lessonId] =&gt; Array
                              (
                                  [lessonIdNumber] =&gt; 40
                              )
  
                      )
  
                  [sessionName] =&gt; PHP and Array
                  [teacherData] =&gt; Array
                      (
                          [teacherName] =&gt; Teacher Name One
                          [teacherId] =&gt; 229910
                      )
  
                  [countStudent] =&gt; 2
                  [examResult] =&gt; Array
                      (
                          [0] =&gt; Array
                              (
                                  [studentGender] =&gt; Male
                                  [studentName] =&gt; Array
                                      (
                                          [0] =&gt; Array
                                              (
                                                  [name] =&gt; George
                                                  [result] =&gt; 98
                                              )
  
                                          [1] =&gt; Array
                                              (
                                                  [name] =&gt; Leonard
                                                  [result] =&gt; 84
                                              )
  
                                      )
  
                              )
  
                      )
  
              )
  
          [1] =&gt; Array
              (
                  [university] =&gt; Array
                      (
                          [name] =&gt; Tes Name
                          [address] =&gt; Street name
                          [province] =&gt; Province name
                      )
  
                  [college] =&gt; Array
                      (
                          [name] =&gt; IT
                      )
  
                  [examDate] =&gt; 2019-01-20
                  [lesson] =&gt; Array
                      (
                          [lessonId] =&gt; Array
                              (
                                  [lessonIdNumber] =&gt; 41
                              )
  
                      )
  
                  [sessionName] =&gt; Photoshop
                  [teacherData] =&gt; Array
                      (
                          [teacherName] =&gt; Teacher Name Two
                          [teacherId] =&gt; 981881
                      )
  
                  [countStudent] =&gt; 1
                  [examResult] =&gt; Array
                      (
                          [studentGender] =&gt; Female
                          [examDate] =&gt; 2019-01-20
                          [lessonId] =&gt; Array
                              (
                                  [lessonIdNumber] =&gt; 40
                              )
  
                          [countStudent] =&gt; 1
                          [studentName] =&gt; Array
                              (
                                  [0] =&gt; Array
                                      (
                                          [name] =&gt; Anita
                                          [result] =&gt; 71
                                      )
  
                              )
  
                      )
  
              )
  
          [2] =&gt; Array
              (
                  [university] =&gt; Array
                      (
                          [name] =&gt; Tes Name
                          [address] =&gt; Street name
                          [province] =&gt; Province name
                      )
  
                  [college] =&gt; Array
                      (
                          [name] =&gt; Design Graphics
                      )
  
                  [examDate] =&gt; 2019-01-20
                  [lesson] =&gt; Array
                      (
                          [lessonId] =&gt; Array
                              (
                                  [lessonIdNumber] =&gt; 42
                              )
  
                      )
  
                  [sessionName] =&gt; Coreldraw
                  [teacherData] =&gt; Array
                      (
                          [teacherName] =&gt; Teacher Name Three
                          [teacherId] =&gt; 327718
                      )
  
                  [countStudent] =&gt; 3
                  [examResult] =&gt; Array
                      (
                          [0] =&gt; Array
                              (
                                  [studentGender] =&gt; Male
                                  [studentName] =&gt; Array
                                      (
                                          [0] =&gt; Array
                                              (
                                                  [name] =&gt; Edward
                                                  [result] =&gt; 83
                                              )
  
                                          [1] =&gt; Array
                                              (
                                                  [name] =&gt; William
                                                  [result] =&gt; 86
                                              )
  
                                          [2] =&gt; Array
                                              (
                                                  [name] =&gt; Oliver
                                                  [result] =&gt; 77
                                              )
  
                                      )
  
                              )
  
                      )
  
              )
  
          [3] =&gt; Array
              (
                  [university] =&gt; Array
                      (
                          [name] =&gt; Tes Name
                          [address] =&gt; Street name
                          [province] =&gt; Province name
                      )
  
                  [college] =&gt; Array
                      (
                          [name] =&gt; Design Graphics
                      )
  
                  [examDate] =&gt; 2019-01-20
                  [lesson] =&gt; Array
                      (
                          [lessonId] =&gt; Array
                              (
                                  [lessonIdNumber] =&gt; 42
                              )
  
                      )
  
                  [sessionName] =&gt; Coreldraw
                  [teacherData] =&gt; Array
                      (
                          [teacherName] =&gt; Teacher Name Three
                          [teacherId] =&gt; 327718
                      )
  
                  [countStudent] =&gt; 2
                  [examResult] =&gt; Array
                      (
                          [0] =&gt; Array
                              (
                                  [studentGender] =&gt; Female
                                  [studentName] =&gt; Array
                                      (
                                          [0] =&gt; Array
                                              (
                                                  [name] =&gt; Isabel
                                                  [result] =&gt; 77
                                              )
  
                                          [1] =&gt; Array
                                              (
                                                  [name] =&gt; Dorothi
                                                  [result] =&gt; 86
                                              )
  
                                      )
  
                              )
  
                      )
  
              )
  
      )
  </code></pre>
  
  <p>)
  </p>
  
  <p>Result array : <a href="https://3v4l.org/lVFlF" rel="nofollow noreferrer">https://3v4l.org/lVFlF</a></p>
  
  <p>I hope my question is clear and get solution. Thank you for your assistance.</p>