2011-07-13 33 views
0

更新:好的,謝謝大家。但是,當我與$ i取代VAR現在得到這些錯誤:排序php數據var

array_multisort()[function.array-multisort]: Argument #1 is expected to be an array or a sort flag

max()[function.max]: When only one parameter is given, it must be an array


這應該是很容易跟着看我的代碼,但誰能告訴我爲什麼我當我運行我的代碼時出現此錯誤?

Parse error: syntax error, unexpected T_VAR

我想通過玩家數對數據進行排序,然後在最高點行應該紅色:

file1.php

<!doctype html public "-//W3C//DTD HTML 4.0 //EN"> 
<html> 
<head> 
<title>Fantasy Football</title> 
</head> 
<body> 
<form action="roster.php" method="POST"> 
<table border="1"> 
<tr><td>Player Name</td><td><input type="text" name="name"</td></tr> 
<tr><td>Position</td><td><input type="text" name="position"</td></tr> 
<tr><td>Number</td><td><input type="text" name="number"</td></tr> 
<tr><td>Team</td><td><input type="text" name="team"</td></tr> 
<tr><td>Points per game</td><td><input type="text" name="points"</td></tr> 
<tr><td colspan="2" align="center"><input type="submit"></td></tr> 
</table> 
</form> 
</body> 
</html> 

roster.php

<?php 
for($i = 0; $i < sizeof($players); $i++) { 
list($name[],$team[],$number[],$position[],$points[]) = explode('|', $players[$i]); 
} 
array_multisort($number, $position, $name, $team, $points, SORT_DESC); 
var mostPoints = max($points); 
for($i = 0; $i < sizeof($players); $i++) { 
if($points[$i]==mostPoints){ 
echo '<tr style="background:#F44">'; 
}else{ 
echo '<tr>'; 
} 
echo '<td>'.$name[$i].'</td><td>'.$team[$i].'</td><td>'.$number[$i].'</td> 
<td>'.$position [$i].'</td><td>'.$points[$i].'</td></tr>'; 
} 

?> 

回答

3
var mostPoints = max($points); 

最近您是否使用JavaScript(或舊的PHP 4 OO)?

PHP的var關鍵字僅用於舊的PHP4風格的對象屬性定義。

刪除var部分。

此外,不要忘記PHP變量sigil $

+1

另請注意,正確的語法是'$ mostPoints = max($ points);' – mc10

+0

@ mc10:謝謝,忘記了這一點。我做了一個編輯。 – alex