PHP与js遍历的区别,PHP运行原理学习

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo 'PHP的第一个执行程序'?></title>
</head>
<body>
    <p>你在干么<?echo '小可爱'?></p>
</body>
</html>

<!-- <?php
var_dump($_SERVER);
?> -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>BMW</title>
</head>
<body>
    <!-- 1 -->
    <H2>交通工具</H2>
    <ol>
        <li>
            <a href="">火车</a>
        </li>
        <li>
            <a href="">地铁</a>
        </li>
        <li>
            <a href="">飞机</a>
        </li>
    </ol>
</body>
</html>
    <!-- 2 -->
    <H2><?echo '交通工具'?></H2>
    <ol>
        <li>
            <a href=""><?echo '火车'?></a>
        </li>
        <li>
            <a href=""><?echo '地铁'?></a>
        </li>
        <li>
            <a href=""><?echo '飞机'?></a>
        </li>
    </ol>
    <!-- 3 -->
    <?php
    // 1.从数据库中取若干条数据 php mysql sql 读数据返回值
    // 2.JS遍历for...forEach   | php遍历foreach  for

    // 模拟数据库数据集合
    $caes = ['芋圆','仙草','红豆'];
    ?>
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>奶茶小料</title>
        <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.6.0/css/bootstrap.css" rel="stylesheet"> 
    </head>
    <body>
        <!-- 使用了php的模板语法 :{
           -->
        <h2><?php echo '夏日清凉'?></h2>
        <ol>
            <?php foreach ($caes as $car) :?>
            <li style ='color:red'>
            <a href=''><?php echo $car?></a>
            </li>
            <?php endforeach?>
        </ol>

        <script>
            let caes =['芋圆','仙草','红豆'];
            for (let i = 0; i<caes.length;i++){
                alert(caes[i]);
            }
        </script>
    
    </body>
    </html>

    <!-- 4. -->
     <?php
    //  php变量 =是赋值符号
    // 1.PHP变量的类型是由内容所决定的
    // 2.php变量的命名一定要有意义  望文生义
    // 3.PHP变量命名 多个单词使用驼峰法命名$userNameCccDdd
       $username = 'peter';
       $username = 12;
       $password = md5('123456');
    //    echo $password;
       echo $username;
       var_dump( $username );

  

 

posted @ 2024-07-02 09:55  好好学习天天向上上上  阅读(6)  评论(0编辑  收藏  举报