PHP比较2个数组并在匹配时添加字段

I have arrays dishesand favorites. My goals is to add a field to the dishes array if a certain dish occurs in the favoritesone. This is what I have tried but it doesn't seem to be working since I get an empty array back.

$boundDishes = [];

foreach ($dishes as $dish) {
    foreach ($favorites as $favorite) {
        if ($favorite == $dish) {
            $dishes['favorite'] = true;
            $boundDishes[] = $dish;
        }
    }
}
return $boundDishes;

Am I doing something wrong or is there a better way?

Any help is very much appreciated!

Many thanks in advance!!

To make this an answer, you are returning $boundGames but not adding anything to it so that's why it's empty, did you mean to add to $boundGames instead of $boundDishes in your loop as below?

$boundGames = [];

foreach($dishes as $dish) {
    foreach($favorites as $favorite) {
        if($favorite == $dish) {
            $dishes['favorite'] = true;
            $boundGames[] = $dishes;
        }
    }
}
return $boundGames;

Alternatively, did you mean to return $boundDishes?

<?php

$dishes =
[
    'chips',
    'hummus',
    'eggs',
    'ham'
];


$favourites =
[
    'spam',
    'hummus'
];

foreach($favourites as $favourite) {
    if(!in_array($favourite, $dishes)) {
        $dishes[] = $favourite;
    }
}

var_export($dishes);

Output:

array (
  0 => 'chips',
  1 => 'hummus',
  2 => 'eggs',
  3 => 'ham',
  4 => 'spam',
)

Or just merge and then filter unique values:

$dishes = array_unique(array_merge($dishes, $favourites))

Perhaps you just need a helper function:

$is_favourite = function($dish) use ($favourites) {
    return in_array($dish, $favourites);
};

echo $is_favourite('spam') ? 'They love spam!' : '';

Is this what you mean?

$boundDishes = [];

foreach ($dishes as $dish) {
    if (in_array($dish, $favourites)) {
        $boundDishes[] = $dish;
    }
}
return $boundDishes;