-4

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 ?

Demolog
  • 105
  • 2
  • 9
  • 1
    If you really need to do it: `array_walk($myArray, function(&$value) { $value['start'] = $value['start']->format('Y-m-d H:i:s.u'); $value['end'] = $value['end']->format('Y-m-d H:i:s.u'); });` though why can't you work with the objects? – Mark Baker May 09 '16 at 22:44
  • I using jquery full calendar, and he require simple format array. – Demolog May 09 '16 at 22:52
  • DateTime objects are a bit special there: http://stackoverflow.com/q/14084222/3933332 – Rizier123 May 10 '16 at 04:09

1 Answers1

1

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.

Eloy Fernández Franco
  • 1,350
  • 1
  • 24
  • 47