How to define an array: 1. Use the "array(value 1, value e2...)" statement; 2. Use "array(key1=>value 1,key2=>value 2.. ..)" statement; 3. Use the "$a[key1]=value 1;$a[key2]=value 2;..." statement; 4. Define it through square brackets "[]".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
The array in PHP is actually an ordered mapping. A map is a type that associates values to keys. This type is optimized in many ways, so it can be treated as a real array, or list (vector), hash table (which is an implementation of map), dictionary, set, stack, queue and many more possibilities. Since the value of an array element can also be another array, tree structures and multidimensional arrays are also allowed.
Generally speaking, the definition methods are as follows:
Method 1:
$a=array(value1,value2,value4,value5,value6...);
Example:
<?php $array=array('a','b','c'); $array[]='simon'; print_r($array); ?>
The running results are as follows shown.
Array ( [0]=>a [1]=>b [2]=>c [3]=>simon )
Method 2:
$a=array(key1=>value1,key2=>value2,key3=>value3);
Method 3:
$a[key1]=value1; $a[key2]=value2;
Method 4: Passed Brackets [] define the array
You can write like this after version 5.4 of PHP, with the new array abbreviation syntax.
php version 5.3 and previous versions do not accept writing like this...
$data = [ 'start_time' => '123', 'end_time' =>'456' ];
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What are the ways to define arrays in php. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

WebStorm Mac version
Useful JavaScript development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
