I have a PDO Query that returns what appears to be an array $pds. I can loop through this array as follows:
foreach ($pds as $row) {
}
I need to loop through the same array a second time but when I do this there doesn’t appear to be any data in the array. Also I’ve tried to copy the array as follows:
$pds2 = $pds;
Is there a trick I’m missing to use this array twice?
thx
Code:
// Remove Duplicate Locations where words are in a different order
$cityArray = $pds;
foreach ($cityArray as $data) {
$words = explode(' ', $data['city'] . ' ' . $data['region1'] . ' ' . $data['region2'] . ' ' . $data['region3']);
sort($words);
$cityWordsArray[$data['id']] = implode(' ', $words);
}
$cityWordsArray = array_unique($cityWordsArray);
foreach ($pds as $row) {
echo 'hi';
foreach($cityWordsArray as $key=>$value) {
if($row['id'] == $key) {
I’m afraid that
$pdsis not an array, but aPDOStatement.If you want to get as an array, you should use
fetchAllto get the result as an array.Try
$pds = $pds->fetchAll();before the loop.