I want to retrieve my data into a two-dimensional array that I can navigate through with a foreach loop, and be able to add new fields to the array afterwords.
For example
foreach($query_results as $qr)
{
$qr->brand_new_field = retrieve_other_data($qr->first_field, $qr->second_field);
}
Im going around in circles with this but I can
t quite seem to get it right. Any suggestions?
In a foreach loop, the "as’ portion is actually a temporary variable built for that instance, assigned to the value from the subject array. Therefore, modifying $qr won’t do anything, as it’s not part of the array. Does that make sense?
foreach($query_results as $k=>$qr)
{
$query_results[$k]->brand_new_field = retrieve_other_data($qr->first_field, $qr->second_field);
}
Try this.
Also this is off topic, but if you are doing queries within that loop, you are doing it terribly wrong. But that’s for another thread.