JoshuaDempsey Posted February 20, 2013 Share Posted February 20, 2013 I am trying to get user input from the command line, but everytime I run this no matter what I enter I get "hi" returned. I don't know why this isn't working, and was hoping someone could take a quick look at it. Thank you: function getUserInput(){ fwrite(STDOUT, "Enter your choice\n"); $selected = fgets(STDIN); if ($selected = "josh"){ echo "hi"; } else{ break; } } Quote Link to comment https://forums.phpfreaks.com/topic/274739-help-with-an-if-statement/ Share on other sites More sharing options...
Jessica Posted February 20, 2013 Share Posted February 20, 2013 = is assignment. == is comparison. $selected = "josh" will ALWAYS be true. As you've discovered. Quote Link to comment https://forums.phpfreaks.com/topic/274739-help-with-an-if-statement/#findComment-1413703 Share on other sites More sharing options...
JoshuaDempsey Posted February 20, 2013 Author Share Posted February 20, 2013 = is assignment. == is comparison. $selected = "josh" will ALWAYS be true. As you've discovered. Silly me, thank you for the help Jessica, it is very much appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/274739-help-with-an-if-statement/#findComment-1413704 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.