排序php数据var [英] Sorting php data var

查看:99
本文介绍了排序php数据var的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:好的,谢谢大家.但是,当我用$ i替换var时,出现以下错误:

UPDATE: Ok, thanks everyone. But, when I replace var with $ i now get these errors:

array_multisort()[function.array-multisort]:参数1应该是数组或排序标志

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

max()[function.max]:仅给出一个参数时,该参数必须为数组

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


这应该很容易理解我的代码,但是有人可以告诉我为什么我在运行代码时收到此错误吗?


This should be pretty easy to follow looking at my code, but can anyone tell me why I am getting this error when I run my code?

解析错误:语法错误,意外的T_VAR

Parse error: syntax error, unexpected T_VAR

我想按玩家编号对数据进行排序,然后最高点行应显示为红色:

I want to sort the data by player number, and then the highest point row should be colored red:

file1.php

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

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>';
}

?>

推荐答案

var mostPoints = max($points);

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

Have you been using JavaScript a lot lately (or old PHP 4 OO)?

PHP仅将var关键字用于旧的PHP4样式对象属性definitons.

PHP's only use of the var keyword was for old PHP4 style object property definitons.

拖放var部分.

此外,别忘了PHP变量sigil $.

Also, don't forget the PHP variable sigil $.

这篇关于排序php数据var的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆