I’ve written a code for appending the date, month and year variables that are stored in three different variables into an array, and I used the implode function to change that into an appropriate date format; but that is not showing the output as expected.
The code is as follows:
$year = 2012;
$month1 = $_POST["month1"];
$date = $_POST["date"];
$array[] = "{$year}{$month1}{$date}";
$imp = implode('/',$array);
echo $imp;
here $date and $month1 are taken from the form….
the output is displaying as 20121220 but not as 2012/12/20.
What’s wrong with the above code?
Is a valid construct for an array, but it’s not the one you would like to have. It creates an array with one element which consists of a string.
With your implode function you want to implode several different elements to one, so every part of the date should be an element. Like this: