$tempResult = $result1;
不会对对象进行深度复制,只是通过引用原始对象进行复制,因此当您稍后调用
odbc_fetch_array($tempResult)
这和
odbc_fetch_array($result1)
这意味着你只有一个物体。因此,任何后续呼叫
odbc_fetch_array
将在任一变量上耗尽。你可以
clone
$result = odbc_exec($c, $q);
$result1 = odbc_exec($c, $q1);
$resultRows = array();
$response = array();
// save this to a regular array for re-use later
$innerQueryResult = array();
while($rowTemp = odbc_fetch_array($result1)) {
$innerQueryResult []= $rowTemp;
}
while($row = odbc_fetch_array($result)) {
$value = "0";
$other = $row['FIELD'];
// iterate through the inner query result set
foreach ($innerQueryResult as $row1) {
if($row['FIELD'] == $row1 ['FIELD']) {
$value = $row1['FIELD'];
}
}
if($value != "0") {
$resultRows[] = array('FIELD'=>$value, 'OTHER'=>$other);
}
}
$response['data'] = $resultRows;
$fp = fopen('somefile.json', 'w');
fwrite($fp, json_encode($response));
fclose($fp);