Which symbol in php can declare an array

青灯夜游
Release: 2023-03-16 08:30:01
Original
1918 people have browsed it

The "[]" symbol in php can declare an array. Two declaration methods: 1. Use the "$array variable name = [element value]" statement. "[]" can contain multiple value lists, separated by commas. If the value list is omitted, an empty array is declared; 2 , use "$array variable name [subscript] = value" to directly declare the array and assign a value to the specified subscript element.

Which symbol in php can declare an array

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

"[ in php ]" symbol can declare an array.

In PHP, square brackets "[]" are also called "array literals". There are two ways to use them to declare an array.

Method 1. Use “$array variable name=[element value]

"[]" does not contain a value, then an empty array is defined:

Copy after login

Which symbol in php can declare an array

"[]" can also contain multiple value lists, with commas between values Separate;

Copy after login

Which symbol in php can declare an array

"1","a"=>"red",2=>"2","b"=>"green","c"=>"blue"]; var_dump($arr); ?>
Copy after login

Which symbol in php can declare an array

##Method 2, use "$array Variable name [subscript] = value

This method can directly declare an array and assign a value to the specified subscript element.

The subscript (index value) can be a string or an integer, and the subscript needs to be wrapped with

[ ].

Example 1:

Copy after login

Output result:

Which symbol in php can declare an array

Example 2:

Copy after login
Output result:

Which symbol in php can declare an array

It can be seen that when we do not specify a specific index value within square brackets, the default is a numeric index, and the index value increases sequentially starting from 0 by default.

Recommended learning: "

PHP Video Tutorial"

The above is the detailed content of Which symbol in php can declare an array. 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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!