RE: [PHP] Re: string comparison

From: Date: Fri, 23 Aug 2002 13:22:47 +0000
Subject: RE: [PHP] Re: string comparison
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-113760@lists.php.net to get a copy of this message
> Would both of these generate the same result? > > Is there an advantage of one over the other? > > 1) if (strcmp($section, 'logout')) > > 2) if ($section == 'logout')) strcmp() returns 0 if the strings are equal, so as written, they're actually the opposite of each other. (#1 would fail if $section was equal to "logout") (#2 actually wouldn't run because of the extra ')', but I'll ignore that. :) ) Regardless, if you're just looking for a simple compare, #2 could possibly be a little quicker since it's not a function call and only has to return true or false, where #1 can return a negative or positive number depending on which string is "greater". (See the docs for strcmp() ) Jaime Bozza

« previous php.general (#113760) next »