I couldn't quite find the exact solution that I am looking for.
I am trying to create an array from a foreach loop that retains the key. Here is the code I have so far but it only keeps the last value in the array:
foreach($links as $link) {
//runs scrape_amazon function for each of the links
$ret = scrape_amazon($link);
foreach($ret as $key => $value) {
//echo $key;
//echo $value;
$final_results[$key] = $value;
}
}
Could anyone help with a solution to keep all the values and the keys?
Thanks in advance!
$final_resultsbeing an exact copy of$ret(assuming it was empty to begin with). What did you expect to happen?$ret. The above simply creates an exact duplicate of$retand places it in to$final_results, as Jon says.