How can explode(), mktime(), and date() functions be used to format dates in PHP?

To format dates in PHP, you can use the explode() function to split a date string into an array, then use mktime() to convert the array into a Unix timestamp, and finally use the date() function to format the timestamp into the desired date format.

$date_string = "2022-12-31";
$date_array = explode("-", $date_string);
$timestamp = mktime(0, 0, 0, $date_array[1], $date_array[2], $date_array[0]);
$formatted_date = date("Y-m-d", $timestamp);
echo $formatted_date;