我遇到的问题是值在第二个 foreach 循环中被覆盖。我需要设置图像缩略图链接的键并将值设置为图像路径。
$img_thumbs = array('folder/thumb1.jpg','folder/thumb2.jpg','folder/thumb3.jpg');
$img_links = array('folder/image1.jpg','folder/image2.jpg','folder/image3.jpg');
$imgs = array();
foreach($img_links as $img_val)
{
foreach($img_thumbs as $thum_val)
{
$imgs[$thum_val] = $img_val
}
}
print_r($imgs);
输出(注意图像值如何重复最后一个值):
Array (
["folder/thumb1.jpg"] => ["folder/image3.jpg"],
["folder/thumb2.jpg"] => ["folder/image3.jpg"],
["folder/thumb3.jpg"] => ["folder/image3.jpg"]
)
我需要什么:
Array (
["folder/thumb1.jpg"] => ["folder/image1.jpg"],
["folder/thumb2.jpg"] => ["folder/image2.jpg"],
["folder/thumb3.jpg"] => ["folder/image3.jpg"]
)
提前致谢