Multidimensional Array Help
Posted: Tue Jul 18, 2006 12:37 pm
Weirdan | Please use
Weirdan | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hey, Im new to PHP so my question should be pretty straight forward. Im trying to get a Multidimensional Array to show both Canadian and American Artist in a single table. But im having no such luck. Could someone point me in the right direction. ThanksCode: Select all
<html>
<head>
<title>Multidimensional Array"s</title>
</head>
<body>
<?php # Testing Multidimensional Arrays
//Creating the array loop that holds all the needed information
$artist_CDN = array (
1=> 'The Stills',
2=> 'Sam Roberts',
3=> 'Metric',
4=> 'Matthew Good',
5=> 'David Usher',
6=> 'Billy Talent'
);
$artist_US = array(
1=> 'Abandoned Pools',
2=> 'Incubus',
3=> 'The Killers',
4=> 'Phantom Planet',
5=> 'The Strokes',
6=> 'Deathcab for Cutie'
);
//Combining US and CDN
$bands = array ('CDN' => $artist_CDN, 'US' => $artist_US);
// Here I out put the the CDN artist Array.
echo '<p><pre><b>Canadian Bands:</b><br>';
asort($artist_CDN);
foreach ($artist_CDN as $key => $value) {
echo "<i>$value\n</i>";
}
echo '</pre></p>';
// Here I out put the the US artist Array.
echo '<p><pre><b>American Bands:</b><br>';
asort($artist_US);
foreach ($artist_US as $key => $value) {
echo "<i>$value\n</i>";
}
echo '</pre></p>';
//Here I create an Array and add both Countries together
echo '<p><pre><b>Both Canadian and American Bands:</b><br>';
asort($bands);
foreach ($bands['CDN'] as $key => $value) {
echo "<i>$value\n</i>";
}
echo '</pre></p>';
?>
</body>
</html>Weirdan | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]