About us Privacy Disclaimer Contact us
FAQ Help Advertising Feedback
Home Sitemap Search Donate us

  Home > Computer & I'net > Adding/Replacing Arrays...

   Browse by title articles:
   What is hot:

for loops

Arrays Intro

Creating/Accessing Arrays

Adding/Replacing Arrays

Merging Arrays

Counting Arrays

Which Domain Name for me?
Include
Text vs Pictures: Shedding Light on the Debate
Search the Web More Efficiently: Tips, Techniques and Strategies
Prev articles1234567 8 9101112Next articles



Adding/Replacing Arrays


Computer & I'net articlesAdding/Replacing Arrays

by David Stanley    



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";
?>



-----------------
Article by David Stanley. Visit his site http://www.htmlite.com. Reprinted with permission.





Adjusted Cost




  Disclaimer | Privacy | Terms of useCopyright © 2004 Nice2know.com