php入門學習知識點五 關於php數組的幾個基本操作

來源:互聯網
上載者:User

複製代碼 代碼如下:<?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]
?>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.