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

  Home > Computer & I'net > Merging Arrays...

   Browse by title articles:
   What is hot:

for loops

Arrays Intro

Creating/Accessing Arrays

Adding/Replacing Arrays

Merging Arrays

Counting Arrays

Search Engine Rankings for Beginners
Top 5 Qualities to Look for in a Search Engine Optimization Program for your Website
Operators
How to speed up your browser
Prev articles1234567 8 9101112Next articles



Merging Arrays


Computer & I'net articlesMerging Arrays

by David Stanley    



Merging two arrays together is a one step command called array_merge.

First we will start with our original pantry array and a second array :

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


Now to combine them into one...
<?php
$pantry_food = array_merge ($pantry, $pantry2);
?>

The newly formed array called "pantry_food" will contain all 6 entries from the two arrays. The index for pantry_food will appear from 0 to 5. Visually, it would look like this...

$pantry_food[0] = "apples";
$pantry_food[1] = "oranges";
$pantry_food[2] = "bananas";
$pantry_food[3] = "potatoes";
$pantry_food[4] = "bread";
$pantry_food[5] = "tomatoes";




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





Group Work




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