PHP array problem, help!

Source: Internet
Author: User
There is such an array:
$array = Array (
0 =
Array (
' Day ' = ' 2014-3-11 ',
' Count ' = 4,
' Day_0 ' = 3,
' Day_1 ' = 1,
),
1 =
Array (
' Day ' = ' 2014-3-7 ',
' Count ' = 2,
' Day_0 ' = 1,
),
2 =
Array (
' Day ' = ' 2014-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, here is an example of 2014-3-6 to 2014-3-11, the middle interval of five days, want to pass on the date of sorting and interval of days, get the following array:


Add:
March 6 and March 11 difference 5 days, so March 6 there are day_1, day_2, Day_3, Day_4, day_5
March 7 and March 11 difference 4 days, so March 7 there are day_1, day_2, Day_3, Day_4
March 8 and March 11 difference 3 days, so March 8 there are day_1, day_2, Day_3
March 9 and March 11 difference 2 days, so March 9 There are day_1, day_2
March 10 and March 11 are 1 days apart, so there are day_1 on March 10.
March 11 and March 11 difference 0 days, so no day_ ...
...... And so on, a triangle-like array is drawn.

Please help us!!! Thank!


Reply to discussion (solution)

Haven't you got the results yet?

I'll write it for you tomorrow if it doesn't.

But I think your last post looks like the way Xu said it.

Haven't you got the results yet?

I'll write it for you tomorrow if it doesn't.

But I see your last post as if Xu Big said the method ah ah, yes, not out of the results! This array to deal with really trouble Ah!!! Xu Big said the method but I can not write Ah!

I don't know what you're going to do.

I don't know what you're going to do. Look closely at my array and want to draw a triangle-like array.

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));
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.