PHP array details, array details. PHP array explanation: as a C ++ programmer, the array explanation produces some confusion about the PHP array during the PHP development process, which is similar to the C ++ array, there are also some differences. let's look at the PHP array and the array details.
As a C ++ programmer, during the PHP development process, some obfuscation occurs on the PHP array, which is similar to the C ++ array, the following gives a comprehensive analysis of PHP arrays and their differences and relationships with the corresponding data types in C ++.
Array Category:
1. value array: It is also called an index array. it uses numbers (starting from 0) as the array subscript. It is equivalent to a vector in C ++.
2. join array: use a string as the subscript of the array. It is equivalent to map in C ++.
3. multi-dimensional array: each element in the array is also an array. Each element in its subarray can also be an array.
Array declaration:
1. numeric array
A. In the following example, the digital ID key is automatically assigned. $ Names = array ("Peter", "Joe", "Lily"); B. In the following example, we manually allocate a digital ID key. $ Names [0] = "Peter"; $ names [1] = "Joe"; $ names [2] = "Lily"; these ID keys can be used in scripts:
2. join array:
Example 1 $ ages = array ("Peter" => 32, "Joe" => 30, "Lily" => 28); example 2 This example is the same as example 1, it is just another way to create an array. $ Ages ["Peter"] = "32"; $ ages ["Joe"] = "30"; $ ages ["Lily"] = "28 "; use the associated array in the script:
Output of the above script: Peter is 32 years old.
3. multi-dimensional array:
In this example, we have created a multidimensional array with the automatically assigned numeric ID key: $ families = array {"Griffin in" => array {"Peter", "Lois ", "Megan"}, "Quagmire" => array {"Glenn"}, "Brown" => array {"Cleveland", "Loretta", "Junior "}}; echo "Is ". $ families ['grigin'] [2]. "a part of the Griffin family? "; Above code output: Is Megan a part of the Griffin family?
Array traversal
1. for loop traversal the for loop can only traverse the index array.
2. foreach traversal: You can traverse the index array or the associated array to traverse the index array foreach (array_expression as $ value) {loop body ;} traverse the associated array foreach (array_expression as $ key => $ value) {loop body;} A. One-dimensional array traverses the index array
"Lee", "company" => "xx company", "mailbox" => "abc@xx.com"); foreach ($ contact as $ key => $ value) {echo $ key. ":". $ value ;}?> B. multi-dimensional array traversal
$ Table) {echo $ section. "Team members are as follows"; foreach ($ table as $ row) {foreach ($ row as $ value) {echo $ value ;}}/ * Why do you ask hovertree.com */?>
Recommended: http://www.cnblogs.com/roucheng/p/phpdongtai.html
As a C ++ programmer, pipeline produces some obfuscation on the PHP array during the PHP development process. it is similar to the C ++ array and has some differences,...