We are hiring PHP Web Developers (0-2 exp), Please visit career page for more information.

What is an array?
Array is a single variable to hold more than one different type of values. it could be number, string, object or array.

Let’s see an example, now if you want to store three colors in variables mean you can do like below,

$variable_1 = ‘Green’;
$variable_2 = ‘Blue’;
$variable_3 = ‘Red’;

it is easy to store and access if there are only three colors,

how would you manage if there are 100 or 1000 color names, will you create 1000 variables like ($variable_1, $variable_2, $variable_3, $variable_4 ….). it’s crazy.

So here is a solution for that problem, that is array( )

Now, you can create single variable called $colors and store more that one color as you want.

$color = array(‘Green’, ‘Blue’, ‘Red’, ‘Yellow’, ‘Pink’, ”, ”, ”, ”, . . . . . );

Now, colors are called array elements, you can access these elements using index values.


About array in php