Php entry 5 basic operations on php arrays _ php entry _ script

Source: Internet
Author: User
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]
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.