Home > Backend Development > PHP Problem > What is an array in PHP

What is an array in PHP

(*-*)浩
Release: 2023-02-23 18:22:02
Original
2965 people have browsed it

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/>
Copy after login

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/>
Copy after login

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!

Related labels:
php
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