"PHP arrays are very useful for storing all types of information. In this blog I will show a simple example of an array and how it can be used to assist your web design."
PHP array()
To start an array we use the array() function built into PHP:
<?
array();
?>
Ok so thats pretty useless lets make it more useful by adding some data:
$myarray = array('<strong>Data Field One</strong>',
'<u>Data Field Two</u>',
'<div>Data Field Three</div>',
'<a href="http://myspaza.co.uk">Data Field Four</a>');
Ok thats better now we have some data (as primitive as it may be)
Ok, so lets use it:
print $myarray[0];
Would produce the following:
Data Field One
and:
print $myarray[1];
Would produce the following:
Data Field Two
Notice how I used $myarray[0] to get the first array element, this is because the first array element is number zero, which can get confusing so we could have used the following:
$myarray = array(1=>'<strong>Data Field One</strong>',
'<u>Data Field Two</u>',
'<div>Data Field Three</div>',
'<a href="http://myspaza.co.uk">Data Field Four</a>');
By adding 1=> I am naming the first element 1 therefore the following elements will follow suit:
Comments from other users: