npsari Posted May 14, 2008 Share Posted May 14, 2008 Any shorter way to write this code? if($term == '45' OR $term == '98' OR $term == '76' OR $term == '77' OR $term == '998' OR $term == '789' OR $term == '776' OR $term == '87'){ print"The term was correct"; }else{ print"Nice try, not correct"; } Link to comment https://forums.phpfreaks.com/topic/105556-solved-is-there-a-better-saving-space-way-for-this-code/ Share on other sites More sharing options...
haku Posted May 14, 2008 Share Posted May 14, 2008 Kind of, but I suspect its not what you are looking for: echo ($term == '45' OR $term == '98' OR $term == '76' OR $term == '77' OR $term == '998' OR $term == '789' OR $term == '776' OR $term == '87') ? "The term was correct :"Nice try, not correct"; If you were wondering if there is a shorter way to write the if statement, I don't think there is. Link to comment https://forums.phpfreaks.com/topic/105556-solved-is-there-a-better-saving-space-way-for-this-code/#findComment-540728 Share on other sites More sharing options...
npsari Posted May 14, 2008 Author Share Posted May 14, 2008 What about maybe if($term == '45','98','76','77','998','789','776','87'){ print"The term was correct"; }else{ print"Nice try, not correct"; } I wonder if that works, maybe i should try it I just thought someone may know a magic way Link to comment https://forums.phpfreaks.com/topic/105556-solved-is-there-a-better-saving-space-way-for-this-code/#findComment-540730 Share on other sites More sharing options...
haku Posted May 14, 2008 Share Posted May 14, 2008 Try it. I never have. I suspect it's not going to work though. Link to comment https://forums.phpfreaks.com/topic/105556-solved-is-there-a-better-saving-space-way-for-this-code/#findComment-540735 Share on other sites More sharing options...
npsari Posted May 14, 2008 Author Share Posted May 14, 2008 ok, thank you Haku I will see what i can do I might use this $mystring = 'abc'; $findme = 'a'; $pos = strpos($mystring, $findme); if ($pos === false) { echo "The string '$findme' was not found in the string '$mystring'"; } else { echo "The string '$findme' was found in the string '$mystring'"; } Link to comment https://forums.phpfreaks.com/topic/105556-solved-is-there-a-better-saving-space-way-for-this-code/#findComment-540736 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.