我已经通过堆栈的答案搜查,但似乎我无法找到下面的代码的解决方案:变量数组中,而
$servers = array();
while($row = mysql_fetch_array($result))
{
$servers[] = $row['name'] => array('ip' => $row['ip'],'port' => $row['port'],'info' => $row['info'],'purpose' => $row['purpose']),
}
我想要实现的是获取所有的结果,但我收到以下错误:
syntax error, unexpected '=>' (T_DOUBLE_ARROW).
使其像这样只能得到最后一个项目:
while($row = mysql_fetch_array($result)) {
$servers = array(
$row['name'] => array('ip' => $row['ip'],'port' => $row['port'],'info' => $row['info'],'purpose' => $row['purpose']),
);
}
这就是说,$服务器是在while循环,因此使它只索引最后一个项目。我不知道是什么原因导致的意外=>:/
请[停止使用'mysql_ *'函数](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php)。 [这些扩展](http://php.net/manual/en/migration70.removed-exts-sapis.php)已在PHP 7中删除。了解[编写](http://en.wikipedia.org/ wiki/Prepared_statement)语句[PDO](http://php.net/manual/en/pdo.prepared-statements.php)和[MySQLi](http://php.net/manual/en/mysqli.quickstart .prepared-statements.php)并考虑使用PDO,[这真的很简单](http://jayblanchard.net/demystifying_php_pdo.html)。 –