I have two arrays of data to work with, and I'm trying to create a loop that will utilize them both like so.
Array A is a list of keywords. Array B is a list of city names.
I'd like for the following foreach loop to take each keyword and combine it with a city name.When each keyword has been matched successfully to every city in Array B, I'd like the loop to continue on through the Array A values and continue the matching.
It seems simple enough, but using the code below, I have been unable to get it working right. The loop works successfully in grabbing one value from the list of keywords, but it then simply adds every value from array B to that keyword and loops through that way.
My code can be seen below:
<?php
foreach ($keyword_list as $key => $value) {
$keyword = strtolower($value);
//REMOVE COMMAS
$keyword = str_replace(',', '', $keyword);
//ADD HYPHENS
$keyword = str_replace(' ', '-', $keyword);
for ($i = 0; $i < count($content); $i++) {
$content[$i] = trim($content[$i]);
//RE-REPLACE SINGLE QUOTES TO ESCAPED VERSIONS FOR INCLUSION IN HTML DOC (PHP ARRAY)
$content[$i] = str_replace("'", "\'", $content[$i]);
}
$file = strtolower(str_replace(' ', '-', $businessName . '-' . $businessPhone));
$file .= '-' . $keyword;
foreach ($city_list as $key2=>$value2) {
$file .='-' . $cityword;
}
$filename = $file . '.php';
}
?>
So with that code above, the following would be produced as an example...
Google-5555555555-Keyword Here-CityNameOne-CityNameTwo-CityNameThree.php
Instead, I'd like it to work as such...
Google-5555555555-Keyword Here-CityNameOne.php
Google-5555555555-Keyword Here-CityNameTwo.php
Google-5555555555-Keyword Here-CityNameThree.php
I thought this would be easy but I'm learning as I go and I'm stumped by what could be causing this issue. If there is anything that I can do to help in resolving it, please advise! I do wish to learn how to do this properly so I'm simply looking for any guidance at all.
Thank you very much for taking the time to read my question.