Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
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."; }
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; } }
Add a comment
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."; }
Do you mean how can you check if two strings contain a certain value?
If so, just use &&:
if($input == "test" && $input2 == "test") {
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();
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.