here is the code

<?php error_reporting(-1);// чекает ошибки $v=$randomc==$randomx ; $randomx=mt_rand(1,6); // от одного до шести $randomc=mt_rand(1,6); //от одного до шести if (($randomx>$randomc)){ echo "победил игрок 1 $randomc , а игрок 2 проиграл $randomx ";} else (($randomc<$randomx));{ echo "победил игрок 2 $randomx , а игрок 1 проиграл $randomc ";} elseif ((v));{ echo "ничья, у вас одинаковые цифры $randomx у 1 и $randomc у воторого";} exit(); ?> 

here's a link to ideone.com

I'm new here and I can not understand what the problem is, why does it give an error in the elseif line?

  • Put your question in order, there is no clear code, and the link does not work. - AivanF.
  • The conditions are correctly written as: if (CONDITION) { BODY; } elseif (ANOTHER_CONDITION) { ANOTHER_BODY; } else { ELSE_BODY; } if (CONDITION) { BODY; } elseif (ANOTHER_CONDITION) { ANOTHER_BODY; } else { ELSE_BODY; } if (CONDITION) { BODY; } elseif (ANOTHER_CONDITION) { ANOTHER_BODY; } else { ELSE_BODY; } and now compare with your code. By the way, ideone showed you where the error is. And more: $v = $randomc == $randomx; Don't you think something is wrong here? - BOPOH
  • You have a little ahtung. See elseif usage examples . - jekaby

2 answers 2

elseif ((v));{ there are several problems here:

  1. elseif itself must go to else, i.e.

  if (условие1) { действия } elseif (условие2, когда не сработало условие1) { действия } else{ действия, которые выполнятся, когда ни одно из перечисленных выше условий не сработало } 
  1. v - without the $ sign, which means that it is not a variable, but a constant that has never been declared before.

  2. after elseif($v) stands ; , which means that the instructions have ended. It must be removed ; and it will work

ps another problem will be with the assignment of $v=$randomc==$randomx ; at the very beginning: here in the variables $randomc and $randomx there are no values ​​yet. It is necessary to move this line after assignment and I would take it in brackets, like this:

 $randomx=mt_rand(1,6); // от одного до шести $randomc=mt_rand(1,6); //от одного до шести $v=($randomc==$randomx); 

    You have a little redundant code and some syntax errors.

     <?php error_reporting(-1);// чекает ошибки $randomx = mt_rand(1, 6); // от одного до шести $randomc = mt_rand(1, 6); // от одного до шести if ($randomx > $randomc) { echo "победил игрок 1 $randomc, а игрок 2 проиграл $randomx "; } elseif ($randomc < $randomx) { echo "победил игрок 2 $randomx, а игрок 1 проиграл $randomc "; } else { echo "ничья, у вас одинаковые цифры $randomx у 1 и $randomc у второго"; } 
    • Thank you very much)))))))))) - M.Semashko