There are three main ways to define arrays in PHP: Indexed arrays: Store elements using numeric index keys. Associative array: uses string key value to store elements. Multidimensional arrays: Store subarrays in array elements.
Array definition methods in PHP
There are three main methods to define arrays in PHP:
1. Index array
In the index array defined, elements are stored with numeric index keys.
<code class="php">$fruits = array("apple", "banana", "orange");</code>
2. Associative array
In an associative array, elements are stored with string key values.
<code class="php">$fruits = array("apple" => "red", "banana" => "yellow", "orange" => "orange");</code>
3. Multidimensional array
Multidimensional array stores subarrays in array elements.
<code class="php">$fruits = array( "apple" => array("red", "green"), "banana" => array("yellow", "green"), "orange" => array("orange", "yellow") );</code>
Additional information:
[]
syntax to define an array. The above is the detailed content of What is the way to define an array in php. For more information, please follow other related articles on the PHP Chinese website!