我有一个 PDO 查询,它返回似乎是数组 $pds 的内容。我可以按如下方式遍历这个数组:
foreach ($pds as $row) {
}
我需要第二次遍历同一个数组,但是当我这样做时,数组中似乎没有任何数据。我还尝试按如下方式复制数组:
$pds2 = $pds;
我错过了两次使用这个数组的技巧吗?
谢谢
代码:
// 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) {