创建一个结果行的副本
如何复制其中有其他关联数组的数组? 我正在讨论从mysql_fetch_assoc
返回的结果集。创建一个结果行的副本
所以说,我有一个这样的结构...
connect
$result = query;
while ($row = mysql_fetch_assoc($result)) {
array_push($static_row, $row); // here lies the problem
}
我想获得的是$static_row
完全一样的$row
副本。最后,我想提出的一个功能,查询和while循环,并简单地返回$static_row
作为参考,$row
一个print_r
看起来像这样
Array ([key1] => value1 [key2] => value2)
Array ([key1] => value1 [key2] => value1)
谢谢, 让我知道如果你需要更多细节
使用形式:
connect $result = query;
while ($row = mysql_fetch_assoc($result))
{
$rows[] = $row;
}
// now you have all the answers in an array of arrays, which you can return from a function
嗯,我不完全确定你要做什么,但它看起来像你有复制分配(应该像这样工作)在循环内。也许这是你的问题。
哦,我...对不起...做了一个小布布有 这是while循环中发生的事情... array_push($ static_row,$ row); 让我编辑上面的东西 – abhishekbh 2009-12-12 03:17:32
@unknown,然后编辑你的问题。 – Don 2009-12-12 03:19:48
你知道什么... nvm ...我正在犯一个非常愚蠢的错误,我刚刚修复了... 它的工作原理应该是 – abhishekbh 2009-12-12 03:21:35
// Fetching all the results to array with one liner:
$result = mysql_query(...);
while(($resultArray[] = mysql_fetch_assoc($result)) || array_pop($resultArray))
+1这比'array_push'更好。 – Franz 2009-12-12 11:19:38