|
<?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入門學習知識點五 關于php數組的幾個基本操作,轉載需保留來源!
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。