gpt4 book ai didi

php - 如何将四个foreach合并为一个foreach?

转载 作者:行者123 更新时间:2023-12-02 07:25:55 25 4
gpt4 key购买 nike

<分区>

我正在尝试将四个 foreach 加到一个 foreach 中。我不知道怎么做,但我正在尝试这样。这是一个例子:

 $images = "image1,image2,image3";
$covers = "cover1,cover2,cover3";
$titles = "title1,title2,title3";
$albums = "album1,album2,album3";

$images = explode(',', $images);
$covers = explode(',', $covers);
$titles = explode(',', $titles);
$albums = explode(',', $albums);

foreach (array_combine($images, $covers) as $image => $cover) {

foreach (array_combine($titles, $albums) as $title => $album) {

echo "$image - $cover - $title - $album</br>"; }}

但是输出是:

image1 - cover1 - title1 - album1
image1 - cover1 - title2 - album2
image1 - cover1 - title3 - album3
image2 - cover2 - title1 - album1
image2 - cover2 - title2 - album2
image2 - cover2 - title3 - album3
image3 - cover3 - title1 - album1
image3 - cover3 - title2 - album2
image3 - cover3 - title3 - album3

需要输出:

image1 - cover1 - title1 - album1
image2 - cover2 - title2 - album2
image3 - cover3 - title3 - album3

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