In PHP there is no need to write the variable type before the variable because it is loosely-typed. It takes datatype from user defined values that are stored in it. Arrays in PHP is a type of data structure that allows to store multiple elements of similar data type under a single variable thereby saving the effort of creating a different variable for every data.
There are basically three types of arrays in PHP:
- Sequential (Indexed) arrays
- Associative arrays
- Multidimensional arrays
Sequential Arrays: Those arrays which have numerical indexes in an ordered sequential manner (starting from 0 and ending with n-1) are called Sequential or Indexed arrays. In PHP, by default array Indexed array.
January February March
Associative arrays: The arrays which are having string type keys instead of indexes or which exist in (‘key’, ‘value’)pairs are called associative arrays.
January February March
How to check if PHP array is associative or sequential?
There is no inbuilt method in PHP to know the type of array. If the sequential array contains n elements then their index lies between 0 to (n-1). So find the array key value and check if it exist in 0 to (n-1) then it is sequential otherwise associative array.
Array is associative
- === It returns True if $x and $y are equal and same type.
- !== It returns True if $x and $y are not equal or not same type.
- == It returns True if $x and $y are equal.
- != It returns True if $x not equal to $y.
- How to remove a key and its value from an associative array in PHP ?
- Multidimensional Associative Array in PHP
- How to loop through an associative array and get the key in PHP?
- Convert an object to associative array in PHP
- How to get numeric index of associative array in PHP?
- How to access an associative array by integer index in PHP?
- PHP program to add item at the beginning of associative array
- Iterate associative array using foreach loop in PHP
- Associative Arrays in PHP
- Sequential Functionality in Node
- Indexed Sequential Search
- How to check whether an array is empty using PHP?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.