gpt4 book ai didi

php - 如何在php中循环传递数组?

转载 作者:可可西里 更新时间:2023-11-01 09:02:08 24 4
gpt4 key购买 nike

我面临的问题是我想通过使用数组和循环显示所有图像,它没有显示所有图像,它只显示一张图像。这是我的代码

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

这里是在数据库中提取出所有图像 in database

使用这段代码,输出只显示一张图片

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

output

我不确定我做的对不对,帮我解决这个问题。谢谢:)

最佳答案

它只显示一张图片,因为你每次循环都要重写 $im_mouths。您应该更改循环以执行以下操作:

$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]);
}
}

我们将 $im_mouths 初始化为一个数组,然后将每个元素作为一个元素添加到数组中:$im_mouths[] = ...

关于php - 如何在php中循环传递数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38559507/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com