An array in PHP is a variable that can hold multiple values at once. Each value is associated with a key (either numeric or named).
Use arrays when you want to group related data.
Indexed arrays use numeric keys (starting from 0):
You can also use the short array syntax:
Associative arrays use named keys instead of numeric indices:
You can also assign values manually:
Arrays inside arrays (2D or more):
PHP provides many built-in functions to work with arrays:
count() – Count number of elementsarray_push() – Add to the endarray_pop() – Remove from the endarray_shift() – Remove from the beginningarray_unshift() – Add to the beginningsort() – Sort indexed arraysasort() – Sort associative arrays by valueksort() – Sort associative arrays by keyUse is_array() to confirm:
Ask the AI if you need help understanding or want to dive deeper into any topic