Php getting started Knowledge Point 5: several basic operations on php arrays. arrays are the most commonly used in php, so you must be familiar with them.
Php getting started Knowledge Point 5: several basic operations on php arrays. arrays are the most commonly used in php, so you must be familiar with them.
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 the for Loop
";
Echo "###################################### ######################
";
For ($ index = 0; $ index Print ("the region in the array". $ index. "$ address [$ index] is
");
}
Echo "###################################### ######################
";
/*
* Array Initialization
*/
Echo "array initialization, and get the number of the current month through the date function, output the content of the corresponding array subject
";
Echo "###################################### ######################
";
$ ArrMonth = array ("January", "February", "March", "l", "May", "June", "July", "August ", "September", "October", "November", "December ");
Date_default_timezone_set ("utc"); // you can specify the default time zone.
$ Month = date ("m ");
Echo "the array structure is ";
Print_r ($ arrMonth );
Echo "current is the". $ month. "month, his English is". $ arrMonth [$ month-1]."
";
Echo "###################################### ######################
";
/*
* Initialize the array, define the key, and then access the array through the key value
*/
Echo "array initialization, define the key, and then access the array through the key
";
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 abbreviation Aug". $ arrMonth ["Aug"]."
";
Echo "###################################### ######################
";
Echo "the following uses Foreach to traverse the Array
";
Echo "###################################### ######################
";
Foreach ($ arrMonth as $ key => $ value ){
Echo "=> the key is $ key and the value is $ value.
";
}
Echo "###################################### ######################
";
/*
* Define multi-dimensional arrays
*/
Echo "defines two-dimensional arrays
";
$ ArrArea = array ("East China" => array ("Fujian", "Zhejiang"), "North China" => array ("Beijing", "Tianjin "));
Echo "East China region =>". $ arrArea ["East China Region"] [0]
?>