How do I write this out properly?
$loccity=array("Atlanta","Boston");
foreach ($loccity as $city) {
$myurl = 'http://$city.mysite.com';
echo $myurl;
}
- Can I just stick $city in the middle of $myurl like that?
- Will using a
foreachloop like this work in this way or is a counter needed?
Yes, it’ll work properly.
Almost.
You forgot that variable interpolation doesn’t work with single quotes, but with double quotes:
Live demo.
You may also want a newline between items:
Live demo.