First, I tried searching for different variations of the title I’ve put for this question, both on Stack Overflow and Google. I couldn’t find a solution.
I am fairly new to PHP. New enough to not know the difference between using eq and == for string comparison!
I usually use == to compare strings in PHP. I am comfortable with it.
But I’ve seen code using eq to compare strings. And I vaguely remember someone making an observation like ‘Oh! I used == to compare strings. I should have used eq‘.
I just want to know whether using == is okay to do simple string comparisons? I am not talking about special cases, case-sensitive, substring or any fancy type of string comparison. Just checking whether apple is the same as apple.
Is == enough? or should I use eq.
My mistake 🙁 thanks a lot for clearing my ‘not-well-researched’ question! It must have been Perl. I got confused seeing the code embedded inside HTML and thought it was a different way of embedding PHP. Sorry.
To accompany my comments: The
eqoperator in Perl tests for string equality, while the==tests for numerical equality only.Even though PHP started once as a collection of Perl scripts, I don’t think, they have copied this operator and this page seems to agree.