php has some similarities with some array applications in other languages. This article mainly shares with you the detailed explanation of PHP array definition and array traversal, hoping to help everyone.
1. Array definition: ① Directly define $[0]='v' ② Use array to define contact=array['a','b']
2. Array type: ① Associative array ② Index array
3. Array traversal:
1. One-bit array traversal:
① Use For loop to traverse
## ② Use foreach to traverse: There are two There are three parameter formats: one is to directly pass the array value to the variable output, and the other is to pass the key value and array value to the variable respectively ③ Use special functions to traverse: each (), list () each ($contact) traverses the elements pointed to by the internal pointer of the current array, moves the pointer backward, and returns after all traversals are completed falselist($var) = $contact Pays the element pointed to by the current array pointer to the variable inside the list. Two-dimensional array traversal: Two-dimensional array traversal uses for or foreach nesting to traverse Related recommendations:
Detailed explanation of several methods of javascript array definition
Several methods of PHP array definition
php array definition and traversal, php array function and multi-dimensional Array
The above is the detailed content of Detailed explanation of PHP array definition and array traversal. For more information, please follow other related articles on the PHP Chinese website!