how to write the code of SWITCH case to give x and y numerical values? x and y are in an array. Data in array came from the data base.
<?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
}
?>
if there is a better and easier way other than switch case please advice
switch/caseis used when you want to compare a single expression to different values. Useif/else iffor more complex conditions.$_POST['round1']have to do with the different cases?if ($array['x'] == 3 && $array['y'] == 1) { ... }