Click to See Complete Forum and Search --> : [RESOLVED] Arrays.


novemberGrey
02-29-2008, 12:27 AM
Okay I have two arrays that looks like this...


$contact = array(
"id"=>"contactSpotlight",
"firstWord"=>"Contact",
"secondWord"=>"Us",
"content"=>"Have any questions? Are you in need of a storage unit? Give us a call or just come on in!",
"link"=>"http://www.spencer-designs.com/Stor-it/contact"
);

$facility = array(
"id"=>"facilitySpotlight",
"firstWord"=>"Our",
"secondWord"=>"Facility",
"content"=>"Facility Content!",
"link"=>"http://www.spencer-designs.com/Stor-it/facility"
);


And here is what the PHP looks like that displays this array...

echo "<div id=\"$contact[id]\" class=\"$class\"><!-- Start: Spotlight -->\n";
echo "<h1>$contact[firstWord]<span>$contact[secondWord]</span></h1>\n";
echo "$contact[content]\n";
echo "<div class=\"learn\"><a href=\"$contact[link]\">Learn More</a></div>\n";
echo "</div><!-- End: Spotlight -->\n";

So I know all about looping and all that stuff, but as you can see this loop will only display the "contact" array...how can I get it to display the "facility" array after it has printed to "contact" array?

novemberGrey
02-29-2008, 01:31 AM
*array after it has printed the "contact" array?

turboraketti
02-29-2008, 01:46 AM
First off; do the echo lines work? Mayby its just me using old versions of php, but expanding other than one-dimensional variables within double quotes needs curly brackets enclosing, like this:
echo "firstWord of contact: {$contact['firstWord']}";

Your question: You could do
foreach( array('contact','facility') as $a ) {
echo "<div id=\"{${$a}['id']}\" class=\"$class\"><!-- Start: Spotlight -->\n";
echo "<h1>{${$a}['firstWord']}<span>{${$a}['secondWord']}</span></h1>\n";
...snip...
}

novemberGrey
02-29-2008, 02:00 AM
It works! Thankyou soooo much!