Thursday, 15 July 2010

php - comparing two strings and determining if they are equal -



php - comparing two strings and determining if they are equal -

i have 2 strings trying compare displaying not equal. problem? here code running.

<?php $x = "come , enjoy show."; $y = "come , enjoy show."; if (strcmp($x, $y)) { echo "they same."; } else { echo "they not same."; } ?>

strcmp - returns 0 on exact match & hence else status executed in case.

defination: returns < 0 if str1 less str2; > 0 if str1 greater str2, , 0 if equal.

change status with,

if (strcmp($x, $y) === 0) { echo "they same."; } else { echo "they not same."; }

demo.

php

No comments:

Post a Comment