我有以下代码片段。问题是,当我打印出数组的结果时,$results
的数据是相同的。应该是[emaid_id] => 1 and [email_id] => 2
。
如何解决此问题?
我使用的是这个代码:
$ex = $stmt->execute();
$stmt->store_result();
$results = array();
$allResults = array();
$params = array();
$meta = $stmt->result_metadata();
if ($meta)
{
while ($field = $meta->fetch_field())
{
$allResults[$field->name] = null;
$params[] = &$allResults[$field->name];
}
call_user_func_array(array($stmt, 'bind_result'), $params);
}
while ($stmt->fetch())
{
$results[] = $allResults;
}
$stmt->free_result();
print_r($results);
输出:
Array
(
[results] => Array
(
[0] => Array
(
[email_id] => 2
[email_sent] => 0
)
[1] => Array
(
[email_id] => 2
[email_sent] => 0
)
)
[success] => 1
[count] => 2
)
我通过将获取循环更改为以下内容来解决问题:
$i = 0;
while ($stmt->fetch())
{
foreach ($allResults as $key => $value)
{
$results[$i][$key] = $value;
}
$i++;
}