Home > Article > Backend Development > What is an array in PHP
#An array in PHP is actually an ordered map. A mapping is a type that associates values to keys.
This type has been optimized in many aspects, so it can be treated as a real array, or list (vector), hash table (an implementation of mapping), dictionary, set , stacks, queues and many more possibilities.
Since the value of an array element can also be another array, tree structures and multidimensional arrays are also allowed.
Define array array() (Recommended learning: PHP programming from entry to proficiency)
You can use the array() language structure to create a new one array. It accepts any number of comma-separated key => value pairs.
array( key => value<br/> , ...<br/> )<br/>// 键(key)可是是一个整数 integer 或字符串 string<br/>// 值(value)可以是任意类型的值<br/>
The comma after the last array element can be omitted. Usually used in single-line array definitions, such as array(1, 2) instead of array(1, 2,). It is common to leave the last comma in multi-line array definitions to make it easier to add a new cell.
Since 5.4, you can use the short array definition syntax, using [] instead of array().
<?php<br/>$array = array(<br/> "foo" => "bar",<br/> "bar" => "foo",<br/>);<br/><br/>// 自 PHP 5.4 起<br/>$array = [<br/> "foo" => "bar",<br/> "bar" => "foo",<br/>];<br/>?><br/>
The above is the detailed content of What is an array in PHP. For more information, please follow other related articles on the PHP Chinese website!