PHP Arrays
In PHP, arrays are data structures that allow you to store multiple values in a single variable. PHP supports three types of arrays:
1. Indexed Arrays
These arrays use numeric indices (starting from 0) to store values.
Shorthand syntax:
2. Associative Arrays
Use named keys (strings) to associate values.
3. Multidimensional Arrays
Arrays containing one or more arrays.
Useful Array Functions
Function | Description |
---|---|
count() |
Counts elements in an array |
array_merge() |
Merges two or more arrays |
array_keys() |
Returns all the keys of an array |
array_values() |
Returns all the values of an array |
in_array() |
Checks if a value exists in an array |
sort() |
Sorts an indexed array |
asort() |
Sorts an associative array by value |
ksort() |
Sorts an associative array by key |