Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pas array in loop in php?

I am facing the problem is that I want to display all image by using array and loop,it is not showing all image ,it does show only one image.Here is my code

if($objResult['Image_Type'] == '01') {
    $img11 = array($objResult['Image_Name']);
    for ($i=0; $i < count($img11[$i]); $i++) {
        $im_mouths = array($img11[$i]);
    }
}

here is in the database to extract out all image in database

the out put is showing only one image by using this code

<?  echo    $im_mouths[0].'11111'.'<br>';?>
<?  echo    $im_mouths[1].'222222'.'<br>';?>
<?  echo    $im_mouths[2].'333333'.'<br>';?>

output

I am not sure I'm doing correctly or not ,help me out this problem. Thanks :)

like image 760
Soul Coder Avatar asked Mar 29 '26 21:03

Soul Coder


1 Answers

It's only showing one image because you're re-writing $im_mouths each time you loop. You should change your loop to do the following:

$im_mouths = array();
if($objResult['Image_Type'] == '01') {
    $img11 = array($objResult['Image_Name']);
    for ($i=0; $i < count($img11[$i]); $i++) {
        $im_mouths[] = array($img11[$i]);
    }
}

We initialize $im_mouths as an array, then add each element to the array as an element: $im_mouths[] = ....

like image 180
Darren Avatar answered Mar 31 '26 10:03

Darren



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!