How can PHP be used to differentiate between weekend and weekday prices for online bookings?
To differentiate between weekend and weekday prices for online bookings in PHP, you can use the date() function to determine the day of the week and then apply different pricing logic based on whether it is a weekday or weekend.
// Get the current day of the week
$dayOfWeek = date('N');
// Set default price
$price = 100;
// Check if it's a weekend (Saturday or Sunday)
if ($dayOfWeek >= 6) {
$price = 150; // Weekend price
}
echo "Price for booking: $" . $price;
Related Questions
- What are the best practices for securely handling and storing passwords in PHP applications, especially for scenarios like creating a password directory?
- Are there any best practices or recommended approaches for handling nested sets in PHP databases?
- What are best practices for assigning variables in PHP to avoid errors like "Illegal string offset"?