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.
$fruits = array("apple", "banana", "orange");
2. Associative array
In an associative array, elements are stored with string key values.
$fruits = array("apple" => "red", "banana" => "yellow", "orange" => "orange");
3. Multidimensional array
Multidimensional array stores subarrays in array elements.
$fruits = array( "apple" => array("red", "green"), "banana" => array("yellow", "green"), "orange" => array("orange", "yellow") );
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!