How can PHP be used to display a user's favorite items on a webpage?

To display a user's favorite items on a webpage using PHP, you can store the user's favorite items in a database table linked to their user ID. Then, retrieve the favorite items associated with the current user and display them on the webpage.

<?php
// Assuming $userId contains the current user's ID
// Connect to database and retrieve favorite items for the user
$favoriteItems = []; // Retrieve favorite items from database based on $userId

// Display favorite items on the webpage
echo "<h2>Your Favorite Items:</h2>";
echo "<ul>";
foreach ($favoriteItems as $item) {
    echo "<li>$item</li>";
}
echo "</ul>";
?>