Assume I have a array like this:
$check="Ninja Turtles";
$key=array("jack and jil","peter likes pan","Ninja Turtles");
I want to find whether the keywords 'Ninja Turtels' in the $check variable exist in the ARRAY and if so I want to know in which INDEX of the ARRAY it exists in. My above code works perfectly fine, but what if my $check variables has some extra words like:
$check="Ninja blah bleh Turtles"
My code won't work then. I want to ignore the 'blah bleh' words in my string.
I managed to work around it with Python because I have years of experience in python but I am new to php.
My Code
foreach (array_values($key) as $i => $val) {
$pos = strpos($check, $val);
if ($pos === false) {
echo "The string '$chechk' was not found in the ARRAY";
} else {
echo "Found '$check' at Postion: '$i'";
}
}
My Full Python Code
check="Ninja bleh balah Turtles"
key=["jack and jil","peter likes pan","Ninja Turtles"]
for index, name in enumerate(KEY):
if(name in phrase):
print("Found", name +" Index is ", index)
active="Found", name +" Index is ", index
break
else:
newkey=name.split()
newphrase=check.split()
num = 2
l = [i for i in newkey if i in newphrase]
if len(l) >= num:
print('Found', name +" "+ "Index is", index)
active="Found", name +" Index is ", index
break
$chechkwhen you meant$check.