Re: comparing a string
| From: | Rafael | Date: | Tue, 20 Jun 2006 12:26:57 +0000 |
| Subject: | Re: comparing a string | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-238394@lists.php.net to get a copy of this message | ||
(inline)
Ross wrote:
I have a quiz where the ansers are held in a array called $correct answers. When I compare the string if ($_REQUEST['x']= $correct_answers[$page-1]) { with a double == the answer is always correct with the single = it is always wrong.A single "=" it's an assignment, not a comparison; and though it sometimes work, you shouldn't compare strings with "==", but using string functions, such as strcmp()... or similar_text(), etc.
when I echo out the posted answer and the value from the answers arrray they are correct.
echo "post equals".$_POST['x']." corect answer is".$correct_answers[$page-1];
--
Atentamente / Sincerely,
J. Rafael Salazar Magaña