rhyspaterson Posted May 29, 2007 Share Posted May 29, 2007 Hey guys, Just been playing around with some IF OR arrays and i was wondering if you could shed some light. The following code: if ($arrayTextPlain[1] != "$registrationID" . "1" || $arrayTextPlain[1] != "$registrationID" . "2") { //reg id doesn't match } else { //reg id matches } Returns false. I.e the reg ID's don't match. However, if i switch them around: if ($arrayTextPlain[1] != "$registrationID" . "2" || $arrayTextPlain[1] != "$registrationID" . "1") { //reg id doesn't match } else { //reg id matches } It returns true. The reg ID's do match. Shouldn't the first one work as well? Isn't that the point of an OR statement? Or have i just not got the syntax correct..? (The reg ID's in the array are meant to match with . "1" and . "2" btw) Thanks lads. Quote Link to comment https://forums.phpfreaks.com/topic/53416-if-or-statements/ Share on other sites More sharing options...
rhyspaterson Posted May 29, 2007 Author Share Posted May 29, 2007 No suggestions lads? Quote Link to comment https://forums.phpfreaks.com/topic/53416-if-or-statements/#findComment-263961 Share on other sites More sharing options...
Trium918 Posted May 29, 2007 Share Posted May 29, 2007 No suggestions lads? Where are you defining your array and variables? Quote Link to comment https://forums.phpfreaks.com/topic/53416-if-or-statements/#findComment-263962 Share on other sites More sharing options...
kenrbnsn Posted May 29, 2007 Share Posted May 29, 2007 We need more information. What are the values of "$arrayTextPlain[1]" and "$registrationID"? Ken BTW, don't bump your thread too quickly. Quote Link to comment https://forums.phpfreaks.com/topic/53416-if-or-statements/#findComment-263966 Share on other sites More sharing options...
rhyspaterson Posted May 29, 2007 Author Share Posted May 29, 2007 $registrationID = $_POST['registrationID']; - The input from a form $arrayTextPlain being an array that i have outputted the contents of a file to. $arrayTextPlain[1] being a line in the array. Both are defined just above the IF OR statement. But i mean, it's more the logic and syntax i am confused about. I know for a fact the variables i am comparing match. So theoretically my first IF OR statement should work. Not just the second one. Edit/ sorry for bump. Quote Link to comment https://forums.phpfreaks.com/topic/53416-if-or-statements/#findComment-263971 Share on other sites More sharing options...
per1os Posted May 29, 2007 Share Posted May 29, 2007 Let's do some testing shall we? <?php if ($arrayTextPlain[1] != $registrationID . "2" || $arrayTextPlain[1] != $registrationID . "1") { if ($arrayTextPlain[1] != $registrationID . "2") { echo 'Test1: ' . $arrayTextPlain[1] . ' did eqaul ' . $registrationID . '2<br />'; }else { echo 'Test1: ' .$arrayTextPlain[1] . ' did NOT eqaul ' . $registrationID . '2<br />'; } if ($arrayTextPlain[1] != $registrationID . "1") { echo 'Test2: ' .$arrayTextPlain[1] . ' did eqaul ' . $registrationID . '1<br />'; }else { echo 'Test2: ' .$arrayTextPlain[1] . ' did NOT eqaul ' . $registrationID . '1<br />'; } if ($arrayTextPlain[1] != $registrationID . "1" || $arrayTextPlain[1] != $registrationID . "2") { if ($arrayTextPlain[1] != $registrationID . "1") { echo 'Test3: ' . $arrayTextPlain[1] . ' did eqaul ' . $registrationID . '1<br />'; }else { echo 'Test3: ' .$arrayTextPlain[1] . ' did NOT eqaul ' . $registrationID . '1<br />'; } if ($arrayTextPlain[1] != $registrationID . "2") { echo 'Test4: ' .$arrayTextPlain[1] . ' did eqaul ' . $registrationID . '2<br />'; }else { echo 'Test4: ' .$arrayTextPlain[1] . ' did NOT eqaul ' . $registrationID . '2<br />'; } } else { echo 'Test3 n 4: ' . $arrayTextPlain[1] . ' did NOT eqaul ' . $registrationID . '1 OR<br />'; echo 'Test3 n 4: ' .$arrayTextPlain[1] . ' did NOT eqaul ' . $registrationID . '2<br />'; } } else { echo 'Test1 n 2: ' .$arrayTextPlain[1] . ' did NOT eqaul ' . $registrationID . '2 OR<br />'; echo 'Test1 n 2: ' .$arrayTextPlain[1] . ' did NOT eqaul ' . $registrationID . '1<br />'; } ?> See what prints out and see if there is a reason why it would not be working. Quote Link to comment https://forums.phpfreaks.com/topic/53416-if-or-statements/#findComment-263990 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.