-3

I've just started learning php an hour ago. I've made this code:

$x=2;  
$y=4;  
echo $x;  
echo $y;  

if($x=5) 
{    
    echo "$x";  
}  
else  
{  
    echo "test";  
}

I'm expecting the output: 24test

I'm getting the output: 245

x equals 2 in the beginning. Why is x then changing to 5 when the only thing I do is CHECKING whether x = 5?

I've searched the web and this site for an answer but couldn't find anything. Thanks in advance!

Tony

tony1968
  • 1
  • 2

1 Answers1

0

Note that = is use to assign value while == use to evaluate value within if statement so your code should be

if($x==5) { 

Instead of

if($x=5) {
Osama
  • 2,912
  • 1
  • 12
  • 15
  • Thanks so much for your fast answers! – tony1968 May 14 '17 at 12:37
  • My dear when I start learning I faced the same problems so I know how it will be difficult to see your code not working for not a known reason at the early stage with the time everything will be easy – Osama May 14 '17 at 12:41