Welcome to another tutorial by ReadnTeach.com. By the end of the tutorial you will hopefully of learnt what an array is and and how you can use them.
Arrays are a means of storing lots of values in one place - rather than having lots of variables which slows down the script and Website. There are three types of array:
We will first take a look at the simplest array - the Numeric Array. There are two methods to initiate a numeric array, both are shown below:
Method One:Code :Method Two:
Code :
You'll notice above that arrays use index numbers to refer to values stored in the array. This value always starts at 0 and increases by one each time a new value is added. To output a value in an array you would use the following code:
Code :
Output:Harry is friends with Sarah
The second type of array is an associative array which allows you to associate one value with another within an array. An example below explains how to do this. Again there are two methods:
Method One:Code :Method Two:15, "Jim"=>16, "Sarah"=>18); ?>
Code :
You can then use this type of array to output something like:
Code :
Output:Harry is 15 years old.
Finally we come to multidimensional arrays, which are slightly more complex than the other arrays. They allow you to store arrays within arrays. The code is below, don't worry if you don't understand first time:
Code :array ( "Megane", "Clio", "Scenic" ), "Ford"=>array ( "Fiesta" "Ka" ), "Vauxhall"=>array ( "Astra", "Corsa", ) ); ?>
So that concludes another tutorial by ReadnTeach.com, in the next tutorial we will look at If and If Else statements!
To post comments you must sign in to your account below!
If you do not currently have an account click here to create one now!