zoukankan      html  css  js  c++  java
  • PHP数组的用法

    <?php
    $paper[] = "Copier";
    $paper[] = "Inkjet";
    $paper[0] = "Copier";
    $paper[1] = "Inkjet";
    print_r($paper);
    for ($j = 0 ; $j < 4 ; ++$j)
        echo "$j: $paper[$j]<br>";
    
    $paper['copier'] = "Copier & Multipurpose";
    $paper['inkjet'] = "Inkjet Printer";
    $paper['laser']  = "Laser Printer";
    $paper['photo']  = "Photographic Paper";
    echo $paper['laser'];
    
    $p1 = array("Copier", "Inkjet", "Laser", "Photo");
    echo "p1 element: " . $p1[2] . "<br>";
    $p2 = array('copier' => "Copier & Multipurpose",
                'inkjet' => "Inkjet Printer",
                'laser'  => "Laser Printer",
                'photo'  => "Photographic Paper");
    echo "p2 element: " . $p2['inkjet'] . "<br>";
    foreach ($paper as $item => $description)
        echo "$item: $description<br>";
    while (list($item, $description) = each($paper))
        echo "$item: $description<br>";
    echo "<pre>";
    foreach ($products as $section => $items)
        foreach ($items as $key => $value)
            echo "$section:\t$key\t($value)<br>";
    echo "</pre>";
    
    $paper = array("Copier", "Inkjet", "Laser", "Photo");
    $j = 0;
    foreach ($paper as $item)
    {
        echo "$j: $item<br>";
        ++$j;
    }
    
    $temp = explode(' ', "This is a sentence with seven words");
    $temp = explode('***', "A***sentence***with***asterisks");
    print_r($temp);
    
    $fname   = "Elizabeth";
    $sname   = "Windsor";
    $address = "Buckingham Palace";
    $city    = "London";
    $country = "United Kingdom";
    $contact = compact('fname', 'sname', 'address', 'city', 'country');
    print_r($contact);
    
    $j       = 23;
    $temp    = "Hello";
    $address = "1 Old Street";
    $age     = 61;
    print_r(compact(explode(' ', 'j temp address age')));
    
    ?>
  • 相关阅读:
    将数字转化为字符串
    给定一列数字将其平移n位
    判断回文数的问题
    c语言链表逆序的问题
    python中类属性和实例属性的区别
    python中__repr__()方法
    python中模块和包
    flask如何写一个model
    遍历文件夹下excel文件并且写入一个新excel
    python统计任务耗时
  • 原文地址:https://www.cnblogs.com/findumars/p/2909482.html
Copyright © 2011-2022 走看看