取阵列功能阵列的每个位置值加倍? [英] Fetch array function doubling values in each position of array?
问题描述
我从这个函数得到奇怪的行为。
I am getting strange behaviour from this function.
输入
public function fetch_array($result_set)
{
$rows = array();
while ($row = mysql_fetch_array($result_set))
{
$rows[] = $row;
print_r($row);
break;
}
return $rows;
}
我所做的功能运行一次,但它从我的MySQL查询结果重复的行。
I have made the function run once but it its duplicating a row from my MySQL query result.
输出
Array ( [0] => Sarah [first_name] => Sarah [1] => Palin [second_name] => Palin )
这应该是
正确的输出
Array ( [first_name] => Sarah [second_name] => Palin )
我用这太问题的例子。
I used this SO question example
<一个href=\"http://stackoverflow.com/questions/3442895/use-mysql-fetch-array-with-foreach-instead-of-while\">Use mysql_fetch_array()用foreach()代替,而()
不是我的查询或MySQL结果故障
这是怎么回事错在这里?
What is going wrong here?
推荐答案
这是不是一个错误,它的预期行为 mysql_fetch_array()
的 http://us.php.net/manual/en/function.mysql-fetch-array .PHP
This is not an error, it's the intended behavior of mysql_fetch_array()
http://us.php.net/manual/en/function.mysql-fetch-array.php
您可以设置 result_type的
标志,或者你可以使用 mysql_fetch_assoc()
来代替。 http://us.php.net/manual/en/function .mysql取入assoc.php
You can either set the result_type
flag, or you can just use mysql_fetch_assoc()
instead. http://us.php.net/manual/en/function.mysql-fetch-assoc.php
这篇关于取阵列功能阵列的每个位置值加倍?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!