Home  >  Article  >  Backend Development  >  PHP introductory learning knowledge point 5: Several basic operations on PHP arrays_PHP tutorial

PHP introductory learning knowledge point 5: Several basic operations on PHP arrays_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:27:10842browse

Copy 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 am now Live at $address[1]
";
echo "############################### #########################


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


";
/*
* Array initialization
*/
echo "Initialize the array, get the number of the current month through the date function, and output the content of the relevant array subscript
";
echo "############## ##########################################
" ;
$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 "The array structure is";
print_r ($arrMonth);
echo "The current month is ".$month.", its English is ".$arrMonth[$month-1]."
";
echo "## ################################################ ########


";
/*
*Array initialization, and define keys, and then access the array through key values
*/
echo "Initialize the array, define the keys, and then access the array through the keys
";
echo "###################### ##################################
";
$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 "Access the array through the English abbreviation Aug".$arrMonth["Aug"]."
";
echo "##################################### ####################


";
echo "The following traverses the array through Foreach
" ;
echo "########################################### ###############
";
foreach ($arrMonth as $key=>$value){
echo " =>The 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=>".$arrArea["East China"][0]
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323826.htmlTechArticleCopy the code as follows: ?php /* * Simple array definition and access*/ echo "Simple array definition with access br"; echo "######################################### #################br...
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