Created
September 11, 2013 21:27
-
-
Save phpfiddle/6530012 to your computer and use it in GitHub Desktop.
[ Posted by Justin ] Array Example - Multidimensional
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Made the headers bold on this one. Maybe can use css to do that next time? | |
$cars=array("Dodge"=>array("Avenger","Challenger","Charger","Dart"),"Toyota"=>array("Highlander","Tundra","Corolla"),"Nissan"=>array("Sentra","Altima","Maxima")); | |
foreach($cars as $x=>$x_value) | |
{ | |
echo "<b>Make: $x<br></b>"; | |
foreach($x_value as $y){ | |
echo "$y<br>"; | |
} | |
echo "<br>"; | |
} | |
?> | |
<?php | |
//This code echos only models made by Toyota | |
echo "<br>"; | |
echo "<br>"; | |
echo "<br>"; | |
echo "Make: Toyota"; | |
echo "<br><br>"; | |
$carString = ''; | |
foreach($cars['Toyota'] as $x) | |
{ | |
$carString .= $x.', '; | |
} | |
echo rtrim($carString, ' ,'), "."; | |
//URL FOR HELP ON THIS - http://www.developerdrive.com/2012/01/php-arrays-array-functions-and-multidimensional-arrays/ | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment