Detailed explanation of PHP array definition and array traversal

小云云
Release: 2023-03-22 12:28:01
Original
1227 people have browsed it

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 false

list($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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template