| Home > Computer & I'net > Adding/Replacing Arrays... |
|
|
|||||||||||||||
|
|
|||||||||||||||
|
||||||||||||||||
Adding/Replacing Arrays | |
<?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. | |
| Articles |
•Auto & Trucks•Business•Computer & I'net·General·Apache·CSS·Database·Hardware·HTML·Javascript&DHTML·Linux·MySQL·Operating System·Perl / CGIPHP·Programming·Publishing·Search Engines·Software Problems·SSI·Tips & Tricks·Utilities·Web Design•Family•Food & Drink•Gardening•Health•Other•Pets•Psychology•Spiritual•Travel•Women |
| Calculators |
|