当前位置:Gxlcms > PHP教程 > 用php补全数组中的日期,该如何解决

用php补全数组中的日期,该如何解决

时间:2021-07-01 10:21:17 帮助过:12人阅读

用php补全数组中的日期
//如图如果遇到这样的数组,如何去补齐数组中每一次的period值 缺少的月份让它补齐 实现每一个大数组有12个月份的数组(因为有时候没有前半年 或后半年的月份),每一次的[period]值 补齐为从(201301~201312)的结构。

就是如从201305月开始那就补齐 01~04。如果从10月开始 补齐 01~09. 按月排序每个二维数组。

Array
(
[0] => Array
(
[period] => 201303
[out_count] => 383
)

[1] => Array
(
[period] => 201304
[out_count] => 43
)

[2] => Array
(
[period] => 201306
[out_count] => 2859
)

[3] => Array
(
[period] => 201307
[out_count] => 251
)

[4] => Array
(
[period] => 201309
[out_count] => 807
)

)


//想得到
Array
(
[0] => Array
(
[period] => 201301
[out_count] => 0
)

[1] => Array
(
[period] => 201302
[out_count] => 0
)

[2] => Array
(
[period] => 201303
[out_count] => 0
)

[3] => Array
(
[period] => 201304
[out_count] => 0
)

[4] => Array
(
[period] => 201305
[out_count] => 0
)

[5] => Array
(
[period] => 201306
[out_count] => 0
)

[6] => Array
(
[period] => 201307
[out_count] => 0
)

[7] => Array
(
[period] => 201308
[out_count] => 0
)
[8] => Array
(
[period] => 201309
[out_count] => 0
)

[9] => Array
(
[period] => 201310
[out_count] => 0

人气教程排行