shadowline
Creating/Accessing Arrays << Adding/Replacing Arrays >> Merging Arrays
Once you have an array created, the next usual step is to add items (values) into it. The equals sign is used to do this. Here is our example array started :

<?php
$pantry = array(
   1 => "apples",
   2 => "oranges",
   3 => "bananas"
   );
?>

There are two ways of adding values into an array. The first way is to leave the square brackets blank.

<?php
$pantry[ ] = "potatoes";
$pantry[ ] = "bread";
?>

The above will add the new items onto the end of the current array list. To replace a specific array element to a new value or to add values into a specific spot, the index may be used in the square brackets.

<?php
$pantry[4] = "potatoes";
$pantry[5] = "bread";
?>

In both cases, the values will be added to the end of the current array. Replacing one of the array values is done the same way. Lets replace the potatoes with tomatoes :

<?php
$pantry[4] = "tomatoes";
?>
Creating/Accessing Arrays << Adding/Replacing Arrays >> Merging Arrays
shadow

Advertise in the banner along the top, Click here!

Valid XHTML 1.0 Transitional Valid CSS! Text Link Ads
shadow
shadow