php 将 mysql_fetch_array 传递给 array()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1960830/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
passing mysql_fetch_array to array()
提问by Web Worm
how can i pass mysql_fetch_array() to array()
我如何将 mysql_fetch_array() 传递给 array()
回答by marvin
If you want to use it for multiple results you may want to assign within the while statement. Such as
如果您想将它用于多个结果,您可能需要在 while 语句中进行赋值。如
$query = mysql_query("SELECT * FROM users");
$resultSet = array();
while($result = mysql_fetch_array($query))
{
$resultSet[] = $result;
}
回答by erenon
did you mean:
你的意思是:
$variable = mysql_fetch_array($result); //$variable is now an array
回答by watchout
A shorter version to add multiple results into an array with a while statement
使用 while 语句将多个结果添加到数组中的较短版本
while($r[]=mysql_fetch_array($query));
array_pop($r); // mysql_fetch_array() moves the internal data pointer ahead so last row should be cut off
回答by Chad
mysql_fetch_array() is just a function that outputs an array, so you can simply attach it to any variable, like so:
mysql_fetch_array() 只是一个输出数组的函数,因此您可以简单地将其附加到任何变量,如下所示:
$foo = mysql_fetch_array($bar);

