1

How can I use two or more strings?

This is what I'm using to do just one string.

if ($input == "test") { echo "$imput is equal to test."; } 

4 Answers 4

4

If I understand you correctly, something like this might work best if you have many strings to compare with.

$string = array("foo", "bar", "hello", "world"); foreach ($string as $s) { if ($input == $s) { echo "$input is equal to $s"; break; } } 
Sign up to request clarification or add additional context in comments.

Comments

3

I think this is what you're looking for:

if ($input == "test" && $input2 == "hello") { echo "$input is equal to test and input2 is equal to hello."; } 

Comments

2

Do you mean how can you check if two strings contain a certain value?

If so, just use &&:

if($input == "test" && $input2 == "test") { 

Comments

0

Then you can use

foreach ($dataarray as $string) { if ($input == $string) { echo "Match Found"; break; } } 

Then it results Match Found if it founds the string in the array $dataarray();

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.