Demolog Demolog - 7 months ago 13
PHP Question

Covert php object DateTime to string in two dimensional array

Hi I have array like as

Array
(
[0] => Array
(
[id] => 167
[title] => hhhhh
[start] => DateTime Object
(
[date] => 2016-05-08 00:00:00.000000
[timezone_type] => 3
[timezone] => Europe/Berlin
)

[end] => DateTime Object
(
[date] => 2016-05-10 00:00:00.000000
[timezone_type] => 3
[timezone] => Europe/Berlin
)

)


I need output witouch dateTime Object and Timezone etc, only date. I think that my new array should be look like below.

Array
(
[0] => Array
(
[id] => 167
[title] => hhhhh
[start] => 2016-05-08 00:00:00.000000
[end]=> 2016-06-08 00:00:00000



)


How do it work ?

Answer

I think it can works fine:

$result = array();
foreach($fatherArray as $element)
{
    $result[] = array("id"    => $element["id"],
                      "title" => $element["title"],
                      "start" => $element["start"]->date,
                      "end" => $element["end"]->date,);
}
var_dump($result);

I hope it helps you.