"; echo "########################################## ################
"; $address=array(5); $address[0]="Fuzhou"; $address[1]="Xiamen";"/> "; echo "########################################## ################
"; $address=array(5); $address[0]="Fuzhou"; $address[1]="Xiamen";">

Home >Backend Development >PHP Tutorial >PHP multidimensional array PHP introductory learning knowledge point 5 Several basic operations on PHP arrays

PHP multidimensional array PHP introductory learning knowledge point 5 Several basic operations on PHP arrays

WBOY
WBOYOriginal
2016-07-29 08:46:03834browse

Copy the code The code is as follows:


/*
* Simple array definition and access
*/
echo "Simple array definition and access
";
echo "# ################################################# #########
";
$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 currently live in $address[1]
";
echo "########################## #############################


";
/*
* Array traversal
*/
echo "Array traversal through for loop
";
echo "######################## ################################
";
for($index=0;$index< ;count($address);$index++){
print("The $address[$index] of the ".$index."th area in the array is
");
}
echo "#### ################################################# ######


";
/*
* Array initialization
*/
echo "Array initialization, and get the number of the current month through the date function, and output the relevant array Subject content
";
echo "##################################### ####################
";
$arrM
date_default_timezone_set("utc"); //Set the default time zone
$m
echo "array The structure is ";
print_r($arrMonth);
echo "The current month is ".$month.", its English is ".$arrMonth[$month-1]."
";
echo " ################################################# #########


";
/*
*Array initialization, and define the keys, and then access the array through the key value
*/
echo "Array initialization , and define the key, and then access the array by key
";
echo "############################## ###########################
";
$arrM
,"Aug"=>"August", "Sept"=>"Septmber","Oct"=>"October","Nov"=>"November","Dec"=>"December"
);
echo "Accessed by the English abbreviation Aug Array".$arrMonth["Aug"]."
";
echo "############################ #############################


";
echo "Pass below Foreach traverses the array
";
echo "#################################### #####################
";
foreach ($arrMonth as $key=>$value){
echo " =>key is $key, the value is $value
";
}
echo "############################## #########################


";
/*
* Define multi-dimensional array
*/
echo "Define two-dimensional array
";
$arrArea=array("East China"=>array("Fujian","Zhejiang"),"North China"=>array(" Beijing","Tianjin"));
echo "East China Area=>".$arrArea["East China Area"][0]
?>

The above introduces PHP multi-dimensional arrays. PHP introductory learning knowledge point 5. Several basic operations on PHP arrays, including PHP multi-dimensional arrays. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn