Me, I would have the ingredients for each dish stored in an array with that dish. Since you're looping over the list of dishes, then within that loop you'd loop over the same list again so that you end up comparing every dish against every other dish [insert cleverness here to avoid wasting time comparing two dishes against each other twice, or comparing a dish against itself].
To find out the difference in ingredients between the two dishes then would then involve using array_intersect
and/or array_diff
to find which ingredients in one dish are/aren't in the other: bog-standard school-level set manipulation stuff.
How you calculate the percentage from that ... well, if they have identical lists of ingredients then their intersection has the same number of ingredients as both dishes, and if they don't have any ingredients in common the intersection is empty.
I'm assuming Ingredient
doesn't include quantities, or that's a whole 'nother layer of complication.