20191108数组组合练习案例

20191108数组组合练习案例

<div>输入姓名和成绩:</div>
<form action='' method='post'>
<?php
for($i=0;$i<5;$i++){
?>
<div>
    <input type='text' name='uname[]' placeholder='姓名' size=8>
    ----
    <input type='text' name='score[]' placeholder='成绩' size=4>
</div>
<p />

<?php } ?>
    
<input type='submit' name="btn" value="提交">
</form>

<?php
if(isset($_POST['btn'])){
    $names=$_POST['uname'];
    $scores=$_POST['score'];
    $student_t1=array_combine($names,$scores);//当同键名时这里会有一个bug,只返回第一个键名解决方法用array_multisort();
    //arsort($student_t1);
    //print_r($student_t1);

    array_multisort($scores,SORT_DESC,$names);
    for($i=0;$i<count($scores);$i++){
    echo "姓名:".$names[$i];
    echo "---成绩:".$scores[$i]."<br />";
}


    
}
?>

 

posted @ 2019-11-08 15:23  深夜起来玩游戏  阅读(97)  评论(0编辑  收藏  举报