The problem you are trying to solve could be expressed as "are there any rows, with type=X, whose name contains text Y?"
This is a question the database can answer, without you having to write a loop in PHP. It's quicker to use the database, the database has access to more information about tuning than you do. It's inefficient to basically download the entire subset of the table matching that type to the PHP processor, from the database, probably over a network, in order to answer the query. Let the DB do the work for you. It's also easier to read as SQL is a declarative language, as opposed to the PHP solution being imperative.
public function isRecipeType($ingredients, $type)
{
$sql = "SELECT COUNT(*) AS c ".
"FROM table ".
"WHERE type = ? ".
" AND ? LIKE CONCAT('%', name, '%')";
$rows = execute($sql, $type, $ingredients);
$row = $rows[0];
return $row["c"] > 0;
}
This uses MySQL syntax, if you use another database then replace the last line of the SQL with
" AND ? LIKE '%' || name || '%'";
I have invented an execute
method in your code there, I don't know what database access layer you are using, but no doubt you will have access to something similar.
As another answer says, make sure you have an index on the type
column. The execution plan for this statement will then be: Find all the rows with the matching type (using the index) and then go through the data and apply the LIKE.
Unless more than e.g. 10% of the rows match the type column, then a sequential read over all the data (i.e. not using the index) will be faster than using the index to identify rows and then random-access reading them. But the database will know if that's the case or not, it doesn't hurt to create the index, then the database can use it or not based on this criteria.