dswg47377
2016-05-09 22:39
浏览 55
已采纳

将php对象DateTime转换为二维数组中的字符串

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 ?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • doutang2382 2016-05-09 22:47
    最佳回答

    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.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题