PHP Arrays
Written by admin on December 25th, 2007 in PHP Tutorials, Tutorials.
PHP is able to store data in a wide variety of ways. One way is arrays. The power to
store data seperately and output it multiple times easily.
Arrays carry data seperately once you have defined it. So if you had the data “one” and
“two” you could hanlde these 2 peices of data seperately from one variable. Here is an example of how it is stored:
<?php
$myarray = array(‘one’,‘two’);
?>
Also double quote or single quote can be used unless using complex arrays.
These 2 peices of information are now stored in one array but in 2 peices. To get this
information you do the following:
<?php
echo $myarray[0];
?>
0 is always the first peice of information, 1 will be the second peice and so on.
That is simple arrays but arrays can be used to store information in a way of categorising.
They can change data accordingly.
Here is an example of how it is coded:
<?php
$myarray(‘1′ => “one”);
?>
Some clever people may have worked out what this does but here it is.
It is basically saying, “1″ is equal to “one”. So everytime you go to grab the first peice of
information it will be converted to one.
BUT, this has to be got differently.
It is shown below:
<?php
echo $myarray[1];
?>
The value in the brackets has to correspond to the data you want to be changed.
NOTE: one cannot be converted to 1.
It only works one way.
They are the basics and the startings of advanced arrays.