PHP教程

PHP学习笔记——数组

本文主要是介绍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"; */
    ?>
这篇关于PHP学习笔记——数组的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!