Updating an array inside foreach loop

Im having difficulties with this loop.

My first array contains lesson details and a lesson code
Second array contains lesson code and states if the lesson is complete “yes” or “no”

I want to array_push this status value to the main lessons array.

Here is my code:

  foreach($arrayProgress as $progress){
      foreach($arrayLessons as $lesson){
        if ($lesson[0] === $progress[0]){
            //set checkmark
            array_push($arrayLessons, "yes");
        }else{
            //set checkmark to nothing
            array_push($arrayLessons, "no");
        }
    }
 }

Here is the incorrect result. Notice how the yes/no values appear at the END of the main array.

Array (

[0] => Array(
[0] => DRW1L1
[1] => 1
[2] => DRW
[3] => Draw a fish inside a light bulb )

[1] => Array (
[0] => DRW1L2
[1] => 1
[2] => DRW
[3] => How to draw a bee )

[2] => Array (
[0] => DRW1L3
[1] => 1
[2] => DRW
[3] => Drawing two lovebirds )

[3] => Array (
[0] => DRW1L4
[1] => 1
[2] => DRW
[3] => Drawing a cow )

[4] => yes
[5] => no
[6] => no
[7] => no
)

I want it to look like this

Array (

[0] => Array(
[0] => DRW1L1
[1] => 1
[2] => DRW
[3] => Draw a fish inside a light bulb )
[4] => yes



)

Because of the complexity of what you are doing, I would at this point switch to using objects. Then you have an array of objects rather than an array period.

Design out what all the model needs.

Im not totally sure how to do this. Isnt an array an object?
There must be a simple way to push new data to an inner multi dimensional array.

SOLVED

foreach($arrayProgress as $progress){
    foreach($arrayLessons as $k=>$lesson){
        if ($lesson[0] === $progress[0]){
           //set checkmark
           $arrayLessons[$k][] = 'yes';
        }else{
            //set checkmark to nothing
            $arrayLessons[$k][] = 'no';
      }
   }
  }
Sponsor our Newsletter | Privacy Policy | Terms of Service