如何编写 SWITCH 案例的代码以给出 x 和 y 数值?x 和 y 在一个数组中。数组中的数据来自数据库。
<?php
$main_link = mysqli_connect('localhost', 'root', '','WMYC');
$a1 = mysqli_fetch_array(mysqli_query($main_link, "SELECT * FROM teams WHERE team='t1' AND round='r1'"));
$b1 = mysqli_fetch_array(mysqli_query($main_link, "SELECT * FROM teams WHERE team='t2' AND round='r1'"));
$c1 = mysqli_fetch_array(mysqli_query($main_link, "SELECT * FROM teams WHERE team='t3' AND round='r1'"));
$d1 = mysqli_fetch_array(mysqli_query($main_link, "SELECT * FROM teams WHERE team='t4' AND round='r1'"));
$array = array($a1['xy'], $b1['xy'], $c1['xy'], $d1['xy']);
print_r($array); // will get Array ( [0] => x [1] => y [2] => x [3] => x )
print_r(array_count_values($array)); // will get Array ( [x] => 3 [y] => 1 )
switch(isset($_POST['round1']))
{
case //array_count_values($array) == ( [x] => 3 [y] => 1 ):
//value of x = 1 and value of y= -3
break;
case //array_count_values($array) == ( [x] => 2 [y] => 2 ):
//value of x = 2 and value of y= -2
break;
case //array_count_values($array) == ( [x] => 1 [y] => 3 ):
//value of x = 3 and value of y= -1
break;
case //array_count_values($array) == ( [x] => 4 ):
//value of x = -1
break;
case //array_count_values($array) == ( [y] => 4 ):
//value of y = 1
}
?>
如果有比 switch case 更好更简单的方法请指教
手掌心
杨__羊羊