PHP array problem, help! There is an array like this:
$ Array = array (
0 =>
Array (
'Day' => '2017-3-11 ',
'Count' => 4,
'Day _ 0' => 3,
'Day _ 1' => 1,
),
1 =>
Array (
'Day' => '2017-3-7 ',
'Count' => 2,
'Day _ 0' => 1,
),
2 =>
Array (
'Day' => '2017-3-6 ',
'Count' => 4,
'Day _ 4' => 1,
'Day _ 5' => 1,
),
3 =>
Array (
'Day' => '2014-3-10 ',
'Count' => 10,
'Day _ 0' => 7,
'Day _ 1' => 2,
'Day _ 2' => 1,
),
);
The date interval is not fixed. for example, to, the interval is five days. to sort the date and the number of days, we can obtain the following array:
Supplement:
There are 5 days of difference between July 1 and July 5, so day_1, day_2, day_3, day_4, and day_5 in July.
There are four days different from March 7 in March 11, so day_1, day_2, day_3, and day_4 in March 7.
There are 3 days between March 1 and May 1, so day_1, day_2, and day_3 exist on May 1 ,.
There are two days between June 1 and June 1, so there are day_1 and day_2 on June 1.
There is one day difference between January 1 and January 1, so there is day_1 on January 1 ,.
There is a 0-day gap between June March 11 and June March 11, so there is no day _......
...... And so on.
Please help me !!! Thank you!
Reply to discussion (solution)
No results yet?
I will help you write it if there is no result tomorrow.
But I see that you mentioned the method in your last post.
No results yet?
I will help you write it if there is no result tomorrow.
However, I see that the method has been mentioned in your previous post by xu. Ah, yes, no results yet! This array is really troublesome to process !!! I cannot write the method that xu said!
I don't understand. I don't know what you want to do...
I don't understand. I don't know what you want to do... Look at my array carefully to get an array similar to a triangle.
foreach($array as $v){ $days[]=date("Ymd",strtotime($v['day'])); $ar[date("Ymd",strtotime($v['day']))]=$v;} $arr= range(min($days),max($days));$max = max($arr);foreach($arr as $v){ $d = $max-$v; if(isset($ar[$v])){ $tt[$v]['day']=$ar[$v]['day']; $tt[$v]['count']=$ar[$v]['count']; for($i=1;$i<=$d;$i++) $tt[$v]['day_'.$i]=(int)$ar[$v]['day_'.$i];}else{ $tt[$v]['day']=date("Y-m-j",strtotime($v)); $tt[$v]['count']=0; for($i=1;$i<=$d;$i++) $tt[$v]['day_'.$i]=0;}}print_r(array_values($tt));