从while循环填充数组以返回PHP

从while循环填充数组以返回PHP,php,arrays,return,Php,Arrays,Return,嗨,我正在尝试用“user1”和“score1”之类的索引填充数组以返回函数 我的代码:它会出现未识别的变量错误 $query = 'select * from users order by score desc'; $result = mysql_query($query) or die (mysql_error()); $highscore = array(); $count = '0'; while($row = mysql_fetch_array($result)) { $co

嗨,我正在尝试用“user1”和“score1”之类的索引填充数组以返回函数

我的代码:它会出现未识别的变量错误

$query = 'select * from users order by score desc';
$result = mysql_query($query) or die (mysql_error());
$highscore = array();
$count = '0';

while($row = mysql_fetch_array($result))
{
    $count++;         
    $highscore = array('user' . $count => $row['username'], 'score' . $count => $row['score']);
}

return $highscore;

要使用数值时,应使用数值。。您使用了零的字符串表示形式(
'0'


如果您想要“高分”,您可能需要使用max并只返回1行。

这不就是一个数组吗?@gar-true-我的键盘在那里离开了我一秒钟:p如果是用户自己的个人高分怎么办?@lix查询可以很容易地更改“选择max(分数)”来自username='lix'的用户,但他说他需要它来实现一个函数,大概是为了填充一个表。
$count = 0;
$highscore = array();
while($row = mysql_fetch_array($result))
{       
    $count++; 
    $highscore['user' . $count] = $row['username'];
    $highscore['score' . $count] = $row['score'];
}