我有json数组如下:
{
"class": [
{
"name":"A",
"std":"5"
},
{
"name":"B",
"std":"4"
}, {
"name":"C",
"std":"6"
}, {
"name":"D",
"std":"9"
},{
"name":"Z",
"std":"3"
}, {
"name":"H",
"std":"0"
}, {
"name":"I",
"std":"1"
}
]
}
我已经解码了数组并通过以下代码以表格格式显示它:
$file=getcwd()."/test1.json";
echo $file;
if (file_exists($file)) {
$t=file_get_contents(($file));
$t=json_decode($t);
echo "<pre>";
echo "<table>";
$default=$t->class;
if(isset($t->class) && !empty($t->class)):
foreach($t->class as $value):
arsort($value);
$vaule=(object) $value;
echo "<tr><td>$value->name</td><td>$value->std</td></tr>";
endforeach;
endif;
echo "</table>";
echo "The file exists";
}
else {
echo "The file does not exist";
}
现在它想根据下拉框中的用户选择对数组进行排序,如下所示:
<form action="jason.php" method="POST">
<select name="sort">
<option value="asc">ASCENDING</option>
<option value="desc">DESCENDING</option>
</select>
<select name="sortby">
<option value="name">NAME</option>
<option value="std">STANDARD</option>
</select>
<input type="submit" value="Save"/>
</form>
我试过使用usort()
,但我无法得到答案
任何帮助都会很明显。提前致谢