I trying to solve a bug in my code, i need to get the number of times words appear in a string. It's working fine with single words but i need it to only count the exact sentence (which may contain spaces)
$name = 'apple';
$words = array("apple", "apple juice", "hot apple pie");
$ingredient_count = substr_count($words, $name);
would result in 3, but i only want it to count the exact name, so in this example the result should be 1 because 'apple' on its own only appears 1 time in my array.
$name = 'apple juice';
would also result in 3 but should also be 1
Thank you for any advice