程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> php入門學習知識點五 關於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]
?>

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved