Jump to content

[SOLVED] Is there a better (saving space!) way for this code


npsari

Recommended Posts

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";
}

 

 

:)

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.

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

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'";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.