function starredRecipeList($userId, $recipeId, $page = 1, $toggle = false) { $recipe = new Recipe($recipeId); $user = new User($userId); $starredRecipe = new StarredRecipe($userId); $isStarred = false; foreach ($starredRecipe->recipes() as $recipe1) { if ($recipe->id() == $recipe1->id()) { //echo $recipe->id() . " == ". $recipe1->id(); $isStarred = true; } } if ($toggle) { if ($isStarred) { $starredRecipe->unstarRecipe($userId, $recipeId); } else { $starredRecipe->starRecipe($userId, $recipeId); } } return $starredRecipe->recipes(); }