Jump to content

Match 2 words in string


gvp16

Recommended Posts

<?php
function containsAll($keywords, $haystack)
{
foreach($keywords as $key)
{
	if(!in_array($key, $haystack))
	{
		return false;
	}
}
return true;
}

$keywordInput = "Kids,Hoody";
$keywords = explode(',', $keywordInput);

$haystackInput = "Animal Kids Basic Hoody Blue";
$haystack = explode(' ', $haystackInput);

if(containsAll($keywords, $haystack))
{
echo "All terms included";
}
else
{
echo "Not all terms included";
}

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.