如何复制包含其他关联数组的数组?我说的是从mysql_fetch_assoc返回的结果集。
假设我有一个这样的结构。
connect
$result = query;
while ($row = mysql_fetch_assoc($result)) {
array_push($static_row, $row); // here lies the problem
}我想得到与$row完全一样的$static_row。最后,我希望将查询和while循环放入一个函数中,并简单地返回$static_row
作为参考,$row的print_r如下所示
Array ( [key1] => value1 [key2] => value2 )
Array ( [key1] => value1 [key2] => value1 ) 谢谢,如果你需要更多的细节,请告诉我
发布于 2009-12-12 11:21:43
使用表单:
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发布于 2009-12-12 11:15:41
嗯,我不是很确定你想要做什么,但是看起来你在循环中有一个拷贝赋值(它应该是这样工作的)。也许这就是你的问题。
发布于 2009-12-12 11:28:33
直接从php doc page
// Fetching all the results to array with one liner:
$result = mysql_query(...);
while(($resultArray[] = mysql_fetch_assoc($result)) || array_pop($resultArray))https://stackoverflow.com/questions/1892129
复制相似问题