5
Staff I am creating a PHP language raffle system here an excerpt of the code I started programming but the problem is that there are 19 different combinations This down here is just the first! there is a more practical way to do without using so many IF instruction lines?
<?php
...................
//primeira combinação de acertos
if (($d1=3) && ($d7=3) && ($d8=3) && ($d9=3) && ($d5=3))
echo "ganhou 12 pontos";
if (($d1=2) && ($d7=2) && ($d8=2) && ($d9=2) && ($d5=2))
echo "ganhou 12 pontos";
if (($d1=1) && ($d7=1) && ($d8=1) && ($d9=1) && ($d5=1))
echo "ganhou 12 pontos";
?>
complementing, are 19 combinations of the variables $D1 up to $D15, but apparently the friend solved the question, so it is enough for if( $D1==$D7 && $D7==$D8 && $D8==$D9 && $D9==$D5 ) echo "gained 12 points"; for each of the 19 combinations
It would be good to put the whole logic in the question, as it can have a lot of different ways of solving the problem. If it were just these variables, it would be enough
if( $d1==$d7 && $d7==$d8 && $d8==$d9 && $d9==$d5 )
to see if the numbers are equal; I imagine that it is not just these 5. Click [Edit] and put the game rules in the question, to have the chance to get an answer.– Bacco
Just don’t forget that "=" is attribution. Comparison is "==".
– Marcos Regis
Remember that
=
is assignment and==
is comparison. Beware!– Mastria
Thanks for the help Bacco, Marcos Regis and Mastria
– Fabio Martins
it is possible to reduce using techniques with mathematical equations. but it depends on how the data is modeled.
– Daniel Omine
Can start with
$d1 == 1
or$d1 == 2
depending on the logic of points for it to stayif($d1==1 && $d1==$d7 && $d7==$d8 && $d8==$d9 && $d9==$d5 )
, as the way you edited independent of the number will always give 12 points if they are equal.– Mastria
The logic is that all numbers have to be equal?
– Guilherme Lautert
yes the logic is that all numbers have to be equal, the numbers will be 1, 2 and 3, and the variables $D1 up to $D15, are 19 combinations where the sorter will earn 12 points, this ( $D1==$D7 && $D7==$D8 && $D8==$D9 && $D9==$D5 ) is one of them
– Fabio Martins