Blogger Information
Blog 13
fans 0
comment 0
visits 12220
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP基础-3.18日作业
小毛的博客
Original
650 people have browsed it

1、用foreach实现关联数组的打印;

2、用for循环实现二维索引数组的表格输出

3、php和html混编

<?php 
    header('content-type:text/html;charset=utf-8');
    define('WEBSITE', 'www.php.cn');
    $websitelist = [
    '百度'=>'http://www.baidu.com',
    '谷歌'=>'http://www.google.com',
    'php中文网'=>'http://www.php.cn',
    '网易'=>'http://www.163.com',
    '新浪'=>'http://www.sina.com',
    '搜狐'=>'http://www.sohu.com'];
    echo '<ul>';
    foreach ($websitelist as $siteName => $siteAdress) {
        // echo '<li>'. '<a href='.$siteAdress.'>'.$siteName.'</a></li>';
        echo "<li style='list-style-type:none;float:left;margin-left:40px;'><a href='$siteAdress'>$siteName</a></li>";//比单引号的写法更简单,还不知道副作用

    };

    echo '</ul>';
    $websitelist2 = [
    [0,'百度','http://www.baidu.com'],
    [1,'谷歌','http://www.google.com'],
    [2,'php中文网','http://www.php.cn'],
    [3,'网易','http://www.163.com'],
    [4,'新浪','http://www.sina.com'],
    [5,'搜狐','http://www.sohu.com']];
    $lenth = count($websitelist2);
    echo '<br><br><hr><table style="margin-left:100px;">
            <tr><td>序号</td><td>站点</td><td>网址</td></tr>';

        for($i=0;$i<$lenth;$i++)
        {
            echo '<tr><td>'.$websitelist2[$i][0].'</td><td>'.$websitelist2[$i][1].'</td><td>'.$websitelist2[$i][2].'</td></tr>';}
     ?>
   echo '</table>';

效果图

QQ截图20190319002932.png

总结:

1、数组是数据库操作的基础;

2、php与html混编时,要注意单双引号的使用;

Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post