PHP 以二维数组显示图像



我需要帮助尝试通过循环显示图像数组。我似乎无法获得显示图像的正确路径。这是我的数组数组:

$images = array();
$images[22] = array("id"=>22,"title" => "View of Cologne", "description" => "View of Cologne from atop the Cologne Cathedral", "country" => "Germany", "user" => "João Fernandes", "path" => "6114850721.jpg");
$images[54] = array("id"=>54,"title" => "Arch of Septimus Severus", "description" => "In the Roman Forum", "country" => "Italy", "user" => "Ellie Sullivan", "path" => "9495574327.jpg");
$images[7] = array("id"=>7,"title" => "Lunenburg Port", "description" => "On board a small sailing ship leaving Lunenburg", "country" => "Canada", "user" => "Mark Taylor", "path" => "5856697109.jpg");
$images[19] = array("id"=>19,"title" => "British Museum", "description" => "The library in the British Museum in London", "country" => "United Kingdom", "user" => "Mark Taylor", "path" => "5855729828.jpg");
$images[46] = array("id"=>46,"title" => "Temple of Hephaistos", "description" => "Located on western perimeter of Agora in Athens. Built in 460-415 BCE, it is the best preserved temple of antiquity.", "country" => "Greece", "user" => "Ellie Sullivan", "path" => "8711645510.jpg");
$images[6] = array("id"=>6,"title" => "At the top of Sulpher Mountain", "description" => "At top of Sulpher Mountain near Banff", "country" => "Canada", "user" => "Frantisek Wichterlová", "path" => "6114907897.jpg");

?>

图像本地存储在"我的 PHP 工作区中"的 Travel 文件中。循环遍历数组、获取"路径"并显示该图像的正确方法是什么?

谢谢

没什么不可思议的:

$basepath = './travel/';
foreach ($images as $image) {
    printf('<img src="%s"/>', $basepath . $image['path']);
}

你应该像这样使用 foreach:

foreach ($images as $image) {
    echo $image['path'];
}

最新更新