Jump to content


Photo

String comparison


  • Please log in to reply
2 replies to this topic

#1 praveenhotha

praveenhotha
  • Members
  • PipPip
  • Member
  • 27 posts
  • LocationBangalore

Posted 17 August 2006 - 05:34 AM

foreach($users as $value)
{
    $key=strcmp($search,$value);
    if($key==0)
    {
        reset($users);
        print("<br>Welcome click to view my pages");
        print("<a href='TestPraveenSession.php'>next page</a>");

    }
}
I am trying to compare 2 strings, using strcmp, so how shud the values be given, it is always giving me false, eventhough i gave the same strings in both the arguments.

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 17 August 2006 - 05:50 AM

strcmp returns 0 when the strings are equal.

#3 Jeremysr

Jeremysr
  • Members
  • PipPipPip
  • Advanced Member
  • 199 posts
  • LocationSaskatchewan, Canada

Posted 17 August 2006 - 05:51 AM

Use the == operator instead.

if ($search == $value)





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users