I need to push value to an array from a for loop based on a count number found in the database.
Here is the scenario.
$num_images = 5;
$numb_images = array();
for ($x = 1; $x <= $num_images; $x++) {
#$numb_images[] = array('image' . $x => '_image' . $x);
$numb_images['image' . $x] = "_image" . $x;
}
When I do print_r($numb_images), it will print the following
Array ( [image1] => _image1 [image2] => _image2 [image3] => _image3 [image4] => _image4 [image5] => _image5 )
2 issues. it prints the key with braces [] which I do not want.
2nd thing is, it is printing them all in same row.
This is exactly how I need it to populate
$numb_images = array(
'image1' => '_image1',
'image2' => '_image2',
);
So the image1 => _image1 key/pair needs to be looped from the given number.
Any help will be highly appreciated.
Thanks