Home > Article > Backend Development > There are several definitions of arrays in php
The types defined by PHP arrays include: Index array: Use numeric index to access elements. Associative array: Access elements using string keys. Multidimensional arrays: elements can be other arrays. Named arrays: Named constants as array keys in PHP 7.
Types of PHP array definitions
There are many types of array definitions in PHP:
1. Indexed Arrays
This is the most common array type, which uses numeric indexes to access elements.
<code class="php">$fruits = array("Apple", "Banana", "Orange");</code>
2. Associative Arrays
Also known as hash tables or maps, use string keys to access elements.
<code class="php">$person = array("name" => "John", "age" => 30);</code>
3. Multidimensional Arrays
The elements in the array can be other arrays to create multidimensional arrays.
<code class="php">$matrix = array( array(1, 2), array(3, 4) );</code>
4. Named Arrays
Named arrays were introduced in PHP 7, which allows the definition of named constants as array keys.
<code class="php">const FRUITS = array("Apple", "Banana", "Orange");</code>
The above is the detailed content of There are several definitions of arrays in php. For more information, please follow other related articles on the PHP Chinese website!