What are the methods to define arrays in php?

coldplay.xixi
Release: 2023-03-03 11:36:01
Original
3312 people have browsed it

The methods to define arrays in PHP are: 1. PHP defines the format of the array, the code is [array name=array()]; 2. PHP output array method, the code is [foreach($aa as $val) {echo$val;}].

What are the methods to define arrays in php?

The methods to define arrays in PHP are:

1. The format of PHP array definition:

数组名=array();
Copy after login

For example: $aa=array();//This defines an array,

then assigns values ​​to the elements:

$aa[0]="9016";
 
$aa[1]="9017";
 
$aa[2]="9018";
Copy after login

2, PHP Method of outputting an array:

foreach($aa as $val)
 
{
 
echo$val;
 
}
Copy after login

You can also directly assign a value when defining the array

$aa=array(0=>"9016",1=>"9017";2=>"9018");
Copy after login

3. PHP arrays can also be subscripted with characters, not necessarily numbers. :

$aa["name"]="Joan";
 
$aa["num"]="9018";
 
$aa["email"]=<a href="mailto:abc@abc.com" rel="external nofollow">abc@abc.com</a>;
Copy after login

You can also define the elements of a one-dimensional array as an array, which is a two-dimensional array.

$aa=array("name"=>"joan","num"=>"9018","email"=><a href="mailto:abc@abc.com" rel="external nofollow">abc@abc.com</a>);
Copy after login

At this time, $ cc[0] is also an array, $cc[1] is also an array, and $cc is a two-dimensional array.

Similarly, three-dimensional and four-dimensional arrays can also continue to be defined.

Related learning recommendations:
PHP programming from entry to proficiency

The above is the detailed content of What are the methods to define arrays in php?. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!