Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I can’t figure it out. Every comment helps 😀

>Solution :

Instead of overwrite array every time just use array_push like:

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

Reference:

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading