Multidimensional Arrays
Multidimensional arrays are basically arrays within arrays. So, let's make one.
<? //Our first array is going to be for dairy products: $dairy = array(1 => 'Milk','Cheese','Yogurt');//Our second array is going to be for animals: $animals = array(1 => 'Cow','Duck','Horse','Chicken'); //Now let's pretend we wanted to combine these arrays (I should've chosen something like Months and Years or States and Territories...but I'm sticking with dairy products and farm animals ;) ....) $combined = array('Dairy' => $dairy, 'Animals' => $animals); //Idea: This is the best way to categorize interests for personalized profiles etc.... //Echoing what we've just done... echo "I want to echo Cow! {$combined['animals']['Cow']}"; ?>
Of course, if you're just wanting to echo Cow, just use echo "Cow";...but if you're building things from arrays like drop down menus or if you're collecting interests, this is helpful.
No Comments »
RSS feed for comments on this post. TrackBack URL