Arrays Introduction

There are few ways to store and get values from an array. But the “Key” is the key. Here’s an example for you to try:


$seasons = array(“Autumn”, “Winter”, “Spring”, “Summer”);
print $seasons[0];


To get at what is inside of an array, just type the key number you want to access. In the above code, we’re printing out what is held in the 0 position (Key) in the array. You just type the key number between the square brackets of your array name:

print $seasons[0];

You can also assign this value to another variable:

$array_data = $seasons[0];
print $array_data;

It’s a lot easier using a loop, though. Suppose you wanted to print out all the values in your array. You could do it like this:

$seasons = array(“Autumn”, “Winter”, “Spring”, “Summer”);

print $seasons[0];
print $seasons[1];
print $seasons[2];
print $seasons[3];

Or you could do it with loop:

for ($key_Number = 0; $key_Number < 4; $key_Number++) {
print $seasons[