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