PHP将缺失日期添加到数组(stdClass对象)

时间:2015-10-27 22:13:53

标签: php arrays date datetime

我有一个包含一些员工数据的数组,我需要填补缺少日期的空白,我试过但我不能让它填写缺少的日期

来自搜索范围的

:例如。 2015-10-25至2015-10-26 目前的结果:

   [92] => Array
        (
            [0] => stdClass Object
                (
                    [DT] => 2015-10-26
                    [CheckIn] => Array
                        (
                            [t] => 15:52
                            [label] => success
                        )

                    [CheckOut] => Array
                        (
                            [t] => 19:41
                            [label] => danger
                        )

                    [Hours] => 3.82
                )

    [56] => Array
        (
            [0] => stdClass Object
                (
                    [DT] => 2015-10-25
                    [CheckIn] => Array
                        (
                            [t] => 12:05
                            [label] => danger
                        )

                    [CheckOut] => Array
                        (
                            [t] => 20:09
                            [label] => danger
                        )

                    [Hours] => 8.07
                ),

            [1] => stdClass Object
                (
                    [DT] => 2015-10-26
                    [CheckIn] => Array
                        (
                            [t] => 12:05
                            [label] => danger
                        )

                    [CheckOut] => Array
                        (
                            [t] => 20:09
                            [label] => danger
                        )

                    [Hours] => 8.07
                )

        )

你可以看到第一个缺少第25个,我需要一个循环来填补缺少的日期。

应如下所示:

   [92] => Array
        (
            [0] => stdClass Object
                (
                    [DT] => 2015-10-25
                    [CheckIn] => Array
                        (
                            [t] => NCO
                            [label] => danger
                        )

                    [CheckOut] => Array
                        (
                            [t] => NCO
                            [label] => danger
                        )

                    [Hours] => 3.82
                ),
            [1] => stdClass Object
                (
                    [DT] => 2015-10-26
                    [CheckIn] => Array
                        (
                            [t] => 15:52
                            [label] => success
                        )

                    [CheckOut] => Array
                        (
                            [t] => 19:41
                            [label] => danger
                        )

                    [Hours] => 3.82
                )

    [56] => Array
        (
            [0] => stdClass Object
                (
                    [DT] => 2015-10-25
                    [CheckIn] => Array
                        (
                            [t] => 12:05
                            [label] => danger
                        )

                    [CheckOut] => Array
                        (
                            [t] => 20:09
                            [label] => danger
                        )

                    [Hours] => 8.07
                ),

            [1] => stdClass Object
                (
                    [DT] => 2015-10-26
                    [CheckIn] => Array
                        (
                            [t] => 12:05
                            [label] => danger
                        )

                    [CheckOut] => Array
                        (
                            [t] => 20:09
                            [label] => danger
                        )

                    [Hours] => 8.07
                )

        )

当前循环,也许你可以帮助我实现这个目的:

//this is to join each user by their id
    $result = array();
foreach ($r['d'] as $data) {
  $id = $data->badgenumber;
  if (isset($result[$id])) {
     $result[$id][] = $data;
  } else {
     $result[$id] = array($data);
  }
  $date = $data->DT;
}

谢谢。

0 个答案:

没有答案