Copy Code code as follows:
<?php
/*
* Simple array definition and access
*/
echo "simple array definition and access <br>";
echo "############################################################<br>";
$address =array (5);
$address [0]= "Fuzhou";
$address [1]= "Xiamen";
$address [2]= "Zhangzhou";
$address [3]= "Quanzhou";
$address [4]= "Ningde";
$address [5]= "Nanping";
$address [6]= "Longyan";
echo "I now live in $address[1]<br>";
echo "############################################################<br><br><br>";
/*
* Array Traversal
*/
echo "Array traversal via a For loop <br>";
echo "############################################################<br>";
for ($index =0; $index <count ($address); $index + +) {
Print ("The first in the array", $index. " Regional $address[$index] for <br> ");
}
echo "############################################################<br><br><br>";
/*
* Array Initialization
*/
echo array initialization, and through the date function to get the current month's number, output related array subscript content <br> ";
echo "############################################################<br>";
$arrMonth =array ("January", "February", "March", "April", "may", "June", "July", "August", "September", "October", " November "," December ");
Date_default_timezone_set ("UTC"); Set the default time zone
$month =date ("M");
echo "Array structure";
Print_r ($arrMonth);
Echo "is currently the first". $month. " Month, his English is ". $arrMonth [$month-1]." <br> ";
echo "############################################################<br><br><br>";
/*
* Array initialization, define keys, and then access the array by key value
*/
Echo array initialization, define keys, and then access array <br> via key;
echo "############################################################<br>";
$arrMonth =array ("=>" "January", "Feb" => "February", "Mar" => "March", "APR" => "April", "may" => "may", " June "=>" June "," => "July"
, "Aug" => "August", "Sept" => "Septmber", "Oct" => "October", "Nov" => "November", "Dec" => "December"
);
echo "Access array via initials AUG". $arrMonth ["Aug"]. " <br> ";
echo "############################################################<br><br><br>";
echo "Iterate through the array via foreach <br>";
echo "############################################################<br>";
foreach ($arrMonth as $key => $value) {
echo "=> key is $key, value is $value<br>";
}
echo "############################################################<br><br><br>";
/*
* Define multidimensional arrays
*/
echo "defines two-dimensional array <br>";
$arrArea =array ("East China" =>array ("Fujian", "Zhejiang"), "North China" =>array ("Beijing", "Tianjin"));
echo "East China =>". $arrArea ["East China"][0]
?>