Say I have the following array of strings:
$data_array = array("the dog is hairy", "cats like treats", "my mouse is tired");
I want to write a function that will extract an element from the array based on whether it contains another string.
For example, if the array element contains the string "dog" i want to return the string "the dog is hairy" for use elsewhere.
I tried using a foreach loop but it didn't work:
foreach ($data_array as $sentence){
if (stripos($sentence, "dog")){
echo $sentence;
}
}
What is the best way to go about this?
0could be interpreted as a falsy value.