Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

142
Views
PHP 7.4 string comparison

Can somebody explain why in the first example below the comparison is returning false?

In the second example, you can see that just changing the first character it will return true instead.

What am I missing?

(1 != "1f9bb589-434d-46ce-9b0d-fe101619ce6f") -> bool(false)

vs

(1 != "2f9bb589-434d-46ce-9b0d-fe101619ce6f") -> bool(true)
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The != operator performs a comparison with type juggling. Since the first operand is an int, the comparison is performed numerically, and the second operand is coerced to an int too. This means the first sequence of digits is taken and converted to an int, and everything after it is discarded. In the first example, the first sequence of digits is "1", so you get 1 != 1, which is obviously false. In the second example, you similarly get 1 != 2, which is obviously true.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!