PHP学习笔记——数组

 <?php
    // 在此之前的$addresses没有定义
    echo $addresses[0]; // 无输出
    echo $addresses; // 无输出
    $addresses[0] = "100@100.com";
    $addresses[1] = "111@111.com";
    $addresses[2] = "222@222.com";
    echo $addresses;
    $addresses = array("100@100.com","111@111.com","222@222.com");
    echo $addresses;
    $price['apple'] = 1.00;
    $price['banana'] = 2.00;
    $price['oranger'] = 3.00;
    echo $price;
    $price = array(
        'apple' => 1.00,
        'banana' => 2.00,
        'oranger' => 3.00
    );
    echo $price;
    $number = array(); /* 创建空数组 */
    $color = array('Mike' => "black",'0' => "Brown",'1' => "Green"); /* 错误的代码,后面的键是从0开始的整数 */
    $color = array('Mike' => "black","Brown","Green");
    $family = array('Mike','Depp','Elliot');
    $family[] = "Taylor"; /* $family[3]是"Taylor" */
    $person = array('name' => "Niko");
    $person[] = "S1mple"; /* $person[0] 是 "S1mple" */
    $number = range(2, 5); /* $number = array(2, 3, 4, 5); */
    $letters = range('a', 'z'); /* $letters 保存了字母表 */
    $size = count($family); /* $size = 4 */
    $scores = array(5, 10); 
    $padded = array_pad($scores, 5, 0); /* $padded = array(5, 10, 0, 0, 0); */
    $padded = array_pad($scores, -5, 1); /* $padded = array(1, 1, 1, 5, 10); */
    $values = range('a','e');
    list($m,$n,$o) = $values; /* $m = "a" , $n = "c" , $o = "e"; */
    $order =   array("Tom","Dick","Jack","Helen");
    list($second,$third) = array_slice($order,1,2); /* $second = "Dick",$third = "Jack"; */
    ?>
上一篇:PowerShell - Loops


下一篇:每日五练---P1093 [NOIP2007 普及组] 奖学金