zoukankan      html  css  js  c++  java
  • PHP 二维数组的遍历,数据的输出

      <?php
                        $arr = [ //设置一个二维数组
                                ['id'=>1,'title'=>'产品1','url'=>'./img/images/l3_05.jpg'],
                                ['id'=>2,'title'=>'产品2','url'=>'./img/images/img-wrap2_03.jpg'],
                                ['id'=>3,'title'=>'产品3','url'=>'./img/images/img-wrap3_03.jpg'],
                                ['id'=>4,'title'=>'产品4','url'=>'./img/images/img-wrap4_03.jpg'],
                                ['id'=>5,'title'=>'产品5','url'=>'./img/images/img-wrap5_03.jpg'],
                                ['id'=>6,'title'=>'产品6','url'=>'./img/images/img-wrap6_03.jpg']
                            ]

                    ?>
                    <?php
                    foreach($arr as $aa){  //遍历二维数组  $aa是随便定义的
                        ?>
                        <li>
                            <a href="ylcp.php?id=<?php echo $aa['id']?>"> //这个a标签是跳转ylcp.php?id=<?php echo $aa['id'] 给地址栏添加这个后面的页面就可以根据这个来显示相应的内容
                                <img src="<?php echo $aa['url']?>" alt="">
                                <span><?php echo $aa['title']?></span>
                             </a>
                        </li>
                        <?php
                    }
                    ?>
    --------------------------------------------------------------跳转的页面----------------------------------
    <?php
    if(isset($_GET['id'])){    //判断有没有这个值 如果有就把他赋给了这个$id 
        $id = $_GET['id'];     
    }else{
        header(("location:/"));//如果没有就跳到相应的页面 /是根目录的意思
    }
    // $arr =[];
    switch($id){   //判断上一个页面传过来的值是多少然后输出相应的数组
        case 1:
            $arr =['id'=>1,'title'=>'产品1','url'=>'./img/images/l3_05.jpg'];
        break;
        case 2:
            $arr =['id'=>2,'title'=>'产品2','url'=>'./img/images/img-wrap2_03.jpg'];
        break;
        case 3:
            $arr =['id'=>2,'title'=>'产品3','url'=>'./img/images/img-wrap3_03.jpg'];
        break;
        case 4:
            $arr =['id'=>1,'title'=>'产品4','url'=>'./img/images/img-wrap4_03.jpg'];
        break;
        case 5:
            $arr =['id'=>1,'title'=>'产品5','url'=>'./img/images/img-wrap5_03.jpg'];
        break;
        case 6:
            $arr =['id'=>1,'title'=>'产品6','url'=>'./img/images/img-wrap6_03.jpg'];
        break;
    }

    ?>
      <div class="fl hs">
                            <img src="<?php echo $arr['url']?>" alt=""> //这个是接收的数组里面的图片地址
                            </div>  
                            <div class="fl sjhs">
                                <h2><?php echo $arr['title']?></h2> //接收的数组里面的名称
                            </div>
  • 相关阅读:
    Linux rm命令详解
    标准时间格式("%Y-%m-%dT%H:%M:%S")转化(基于python 3.6)
    通过load json文件读取json指定数据(基于python 3.6)
    遍历win10文件夹并解析json文件,按照json格式存入mongo数据库(基于python 3.6)
    mongo的备份数据库导入现有数据库
    python 获取网页内容新增网页分类+删除指定后缀数组元素功能(基于python 3.6)
    sqlite3的安装和使用(基于python3.5)
    python 获取提交表单网址内容(即需要密码网址)以财务网站为例
    python 分析PDF文件 (基于使用pdf2htmlEX.exe python3.6)
    python 复制多个文件到指定目录(基于python 3.X)
  • 原文地址:https://www.cnblogs.com/sheep-fu/p/12966683.html
Copyright © 2011-2022 走看看