Php 创建结果行的副本
如何复制包含其他关联数组的数组? 我说的是从mysql\u fetch\u assoc返回的结果集 所以说我有一个这样的结构Php 创建结果行的副本,php,arrays,associative,Php,Arrays,Associative,如何复制包含其他关联数组的数组? 我说的是从mysql\u fetch\u assoc返回的结果集 所以说我有一个这样的结构 connect $result = query; while ($row = mysql_fetch_assoc($result)) { array_push($static_row, $row); // here lies the problem } 我想得到的$static\u row完全是$row的副本。最后,我希望将该查询和while循环放入一个函
connect
$result = query;
while ($row = mysql_fetch_assoc($result)) {
array_push($static_row, $row); // here lies the problem
}
我想得到的$static\u row
完全是$row
的副本。最后,我希望将该查询和while循环放入一个函数中,并简单地返回$static\u row
作为参考,$row
的打印\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循环中的内容。。。数组推送($static\u row,$row);让我来编辑上面的东西,你知道吗…nvm…我刚才犯了一个非常愚蠢的错误,我刚刚纠正了这个错误。。。它的工作原理应该是这样的
// Fetching all the results to array with one liner:
$result = mysql_query(...);
while(($resultArray[] = mysql_fetch_assoc($result)) || array_pop($resultArray))