I am comparing two string by
strcmp(1,2)and i am getting “-1 ” insted of 1 my code is below
<?php
echo strcmp(1,2);
?>
output:-1

please let me know why i am getting -1 for false and how to handle it ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
1 is less than 2, strcmp is defined as returning:
Thus the behaviour is expected.
Note the following caveat:
From a comment on the documentation page for
strcmp.PHP is full of this sort of unexpected behaviour. In your situation, I would ensure both arguments were cast as strings to avoid any confusion: