Arrays

Creator:
Tripper

For this tutorial it is recommended you have access to a PHP host.


Arrays can be used to store multiple pieces of information in just 1 variable. Here is an example array


$colors = array('blue','red','green','black');

That is an array, now to call the information, we could


echo $colors[0];
That would output Blue (Remember PHP starts counting at 0, not 1!)

If you wanted to display a random color from the array you could use,


$randy = rand(0,3); echo $colors[$randy];

You could even use a Loop, to display all the colors, but Loops will be left for another tutorial.

Now you should have a basic idea of how to use an Array, and how to display it.

Description:
This tutorial attempts to make you familliar with Arrays in PHP.

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options