<address id="ousso"></address>
<form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
  1. php語言

    php數組的幾個基本操作

    時間:2025-03-15 00:10:05 php語言 我要投稿
    • 相關推薦

    關于php數組的幾個基本操作

      數組是php中最常用的,所以大家一定要熟練的掌握。下面是小編為大家搜集整理出來的有關于php數組的幾個基本操作,一起了解一下吧!

      代碼如下:

      <?php

      /*

      * 簡單的數組定義與訪問

      */

      echo "簡單的數組定義與訪問<br>";

      echo "############################################################<br>";

      $address=array(5);

      $address[0]="福州";

      $address[1]="廈門";

      $address[2]="漳州";

      $address[3]="泉州";

      $address[4]="寧德";

      $address[5]="南平";

      $address[6]="龍巖";

      echo "我現在住在$address[1]<br>";

      echo "############################################################<br><br><br>";

      /*

      * 數組遍歷

      */

      echo "通過for循環進行數組遍歷<br>";

      echo "############################################################<br>";

      for($index=0;$index<count($address);$index++){

      print("數組中第".$index."個的地區$address[$index]為<br>");

      }

      echo "############################################################<br><br><br>";

      /*

      * 數組初始化

      */

      echo "數組初始化,并通過日期函數得到當前月份的數字,輸出相關數組下標的內容<br>";

      echo "############################################################<br>";

      $arrMonth=array("January","February","March","April","May","June","July","August","September","October","November","December");

      date_default_timezone_set("utc"); //設置默認時區

      $month=date("m");

      echo "數組結構為";

      print_r($arrMonth);

      echo "當前是第".$month."月,他的英文是".$arrMonth[$month-1]."<br>";

      echo "############################################################<br><br><br>";

      /*

      *數組初始化,并定義鍵,然后通過鍵值訪問數組

      */

      echo "數組初始化,并定義鍵,然后通過鍵訪問數組<br>";

      echo "############################################################<br>";

      $arrMonth=array("Jan"=>"January","Feb"=>"February","Mar"=>"March","Apr"=>"April","May"=>"May","Jun"=>"June","Jul"=>"July"

      ,"Aug"=>"August","Sept"=>"Septmber","Oct"=>"October","Nov"=>"November","Dec"=>"December"

      );

      echo "通過英文縮寫Aug 訪問數組".$arrMonth["Aug"]."<br>";

      echo "############################################################<br><br><br>";

      echo "下面通過Foreach遍歷數組<br>";

      echo "############################################################<br>";

      foreach ($arrMonth as $key=>$value){

      echo "  =>鍵是$key,值是$value<br>";

      }

      echo "############################################################<br><br><br>";

      /*

      * 定義多維數組

      */

      echo "定義二維數組<br>";

      $arrArea=array("華東地區"=>array("福建","浙江"),"華北地區"=>array("北京","天津"));

      echo "華東地區=>".$arrArea["華東地區"][0]

      ?>


    【php數組的幾個基本操作】相關文章:

    PHP數組基本介紹09-06

    php數組操作方法10-18

    PHP自帶的幾個實用的數組函數08-10

    PHP自帶的幾個實用的數組函數詳解10-07

    Java數組的基本操作方法介紹08-14

    PHP數組的排序09-28

    PHP一般數組與對象數組11-13

    PHP數組函數知識10-24

    php數組操作如何實現鍵名比較與差集、交集賦值10-22

    <address id="ousso"></address>
    <form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
    1. 日日做夜狠狠爱欧美黑人