Home > Article > Backend Development > What are the keywords used to define arrays in php
The keyword defining an array in PHP is array, which is used to create and initialize an array containing key-value pairs. Arrays can be defined using array() or square brackets [], the keys of the array can be strings or numbers, the elements can be of any data type, and the array is dynamic and can grow or shrink as needed.
The keyword that defines an array in PHP
The keyword that defines an array in PHP isarray
. It is used to create and initialize an array and store elements in key-value pairs.
Syntax:
<code class="php">$array_name = array( 'key1' => 'value1', 'key2' => 'value2', ... );</code>
Example:
<code class="php">$fruits = array( 'apple' => 'red', 'banana' => 'yellow', 'orange' => 'orange' );</code>
This example creates a file called fruits
An array containing key-value pairs:
Arrays can also be defined using square bracket syntax:
<code class="php">$colors = ['red', 'blue', 'green'];</code>
Note:
The above is the detailed content of What are the keywords used to define arrays in php. For more information, please follow other related articles on the PHP Chinese website!