0

I have the following code that loops trough an array called projects and each project is an associative array. Then I get the image properties and then I want to add a new element to this associative array with the image properties. But it doesn't get added.

foreach ($projects as $project) {
    $image_dimensions = array(getimagesize('data/'.$project['base_image']));
    $project['image_dimensions'] = $image_dimensions;
}

Why isn't $project['image_dimensions'] getting added to $project?

Nisse Engström
  • 4,738
  • 23
  • 27
  • 42
FutureCake
  • 2,614
  • 3
  • 27
  • 70

1 Answers1

1

Please try with this one. You need to add with all projects all key.

foreach ($projects as $key => $project) {
    $image_dimensions = array(getimagesize('data/'.$project['base_image']));
    $projects[$key]['image_dimensions'] = $image_dimensions;
}
Nisse Engström
  • 4,738
  • 23
  • 27
  • 42
Manraj
  • 205
  • 1
  • 3
  • 10