Originally published on CodingCush .
A PHP array is a single variable that holds many values at once. Instead of three separate variables called $fruit1, $fruit2 and $fruit3, you store all three fruits in one $fruits array and reach each one by position or name. In this guide you will learn the three types of PHP arrays, indexed, associative and multidimensional, plus how to loop through them, add and remove items, and use the everyday array functions. Every example here was run on PHP 8.3.32, so the outputs shown are real.
What Is a PHP Array?
A normal variable holds one value: a string holds one piece of text, a number holds one number. That works fine until you need a list, like the names of five students. An array stores the whole list under one name. Think of a variable as a single pocket and an array as a bag with many labelled pockets. If variables still feel new, our guide to PHP variables, data types and echo in PHP covers them first.…