I have a variable called $day_price that can hold one of two values – either “weekday_price” or “weekend_price“. If I’m echoing $day_price however I would like the value of weekday_price to be echoed as Weekday Price and the value of weekend_price to be echoed as Weekend Price.
How can I achieve this without writing a long if-else statement like this?
if ($day_price=="weekday_price") {
echo "Weekday Price";
}
else if ($day_price=="weekend_price") {
echo "Weekend Price";
}
You can do this without conditions:
For more information see ucwords and str_replace in PHP Manual