显示带有哈希数组链接的图像

时间:2019-01-12 23:56:38

标签: php

我正在尝试显示来自哈希数组中某些链接的图像列表。在我自己的文件夹中的其他图像旁边。预先感谢

    $config = [

   'gallery_name' => 'my_heading',

   'unsplash_categories' => ['array','of','category','keywords'],

   'local_images' => 

   ['folder/jpg1.jpg','folder/jpg2.jpg','folder/jpg1.jpg','folder/jpg4.jpg']

   ];

在HTML中,尝试了什么。

   <?php foreach($config as $my_config => $gallery_name): ?>

    <h1><?php echo $gallery_name; ?></h1>

    <?php endforeach ?>

    <p>  
     <?php foreach($config as $img)
     {
    foreach($img['local_images'] as $local_img)
    {
        echo "<img src='".$local_img['']."' alt=''>.<br>";
    }

    foreach($img['unsplash_categories'] as $unsplash_img)
    {
        echo "<img src='".$unsplash_img['']."' alt=''>.<br>";
    }
    }

 ?>   
 </p>

1 个答案:

答案 0 :(得分:0)

Shaik欢迎来到SO。
不清楚您要实现什么目标,但是如果您只想使用$config作为示例来显示图像,则可以将其简化为如下所示:

<h1><?= $config["gallery_name"]; ?></h1>

<p> 
    <?php
    foreach($config['local_images'] as $local_img)
    {
        echo "<img src='" . $local_img . "' alt=''>.<br>";
    }

    //same for unsplash_categories...
    ?>   
</p>