PHP基础12:数组

<?php

    //1.实例
    $array = array("VOLVO","BMW","SASS");

    for ($i=0; $i < count($array); $i++) {
        echo $array[$i];
        echo "<br>";
    }
    echo "<hr>";

    //2.索引数组的创建方法
    $color = array("red","yello","blue");
    $name[0]="laopo";
    $name[1]="mama";
    $name[2]="baba";
    for ($i=0; $i < count($name); $i++) {
        echo $name[$i];
        echo "<br>";
    }
    echo "<hr>";

    //3.创建关联数组
    $age = array(25,30,35);
    for ($i=0; $i < count($age); $i++) {
        echo $age[$i];
        echo "<br>";
    }

    //4.遍历关联数组
    echo "<hr>";
    $friends=array("peter"=>25,"bob"=>30,"Joe"=>40);
    foreach ($friends as $key => $value) {
        echo "key=".$key.":value=".$value."<br>";
    }
?>
上一篇:蓝桥杯VIP试题 算法训练 最大获利


下一篇:Jenkins持续集成环境, 如何自定义 maven 仓库