Compare 2 arrays, style same values in different manner

Greetings everyone,

I need to print out all of the “ingredients” of the $apple_cake array. If any of the ingredients are also present in the $my_ingredients array, then those need to be printed in bold.

$apple_cake = array("eggs", "flour", "sugar", "butter", "apples", "baking powder", "vanilla extract");
$my_ingredients = array("flour", "sugar", "apples");

Thus 7 ingredients will be echoed out but “flour”, “sugar”, and “apples” will be in bold.

Can this be done?

Thanks in advance!

This should do it.

<?php
$apple_cake = array("eggs", "flour", "sugar", "butter", "apples", "baking powder", "vanilla extract");
$my_ingredients = array("flour", "sugar", "apples");

foreach($apple_cake as $item):
	if(in_array($item,$my_ingredients)){
		echo "<b>" . $item . "</b><br />\\r";
	}else{
		echo $item . "<br />\\r";
	}
endforeach;
?>

Brilliant Drummin!

Just what I was looking for! I did try the in_array function but somehow expected the solution to be more complex.

Thanks for assisting me once again.

Cheers.