Home > OS >  How to add value in the second/child layer of a array
How to add value in the second/child layer of a array

Time:02-07

I'm trying to add a value media_type to every child of the array. The code I'm using is:

while($row = $result->fetch_assoc()) {
  $url = "example";

  $path = $this->get_url($url);

  $popular = ['media_type' => $row["type"],$path];
}

Here's a example of the array.

This content in the array is from themoviedb API. And is opensource.

I can't figure it out. Every comment helps :D

CodePudding user response:

Instead of overwrite array every time just use array_push like:

$popular[] = ['media_type' => $row["type"],$path];

Reference:

  •  Tags:  
  • Related