Such two arrays:
Registration Information $array1 = Array (0=>array (' Day ' = ' 2014-3-7 ',//Registration date ' data ' =>array (0=>array (' uid ' = ' 0000001 '), 1 =>array (' uid ' = ' 0000002 '), 3=>array (' uid ' = ' 0000003 '), 4=>array (' uid ' = ' 0000004 '),)),1=> Array (' Day ' = ' 2014-3-8 ',//Registration date ' data ' =>array (0=>array (' uid ' = ' 0000005 '), 1=>array (' uid ' = " 0000007 '), 2=>array (' uid ' = ' 0000006 '),), 2=>array (' Day ' = ' 2014-3-10 ',//Registration date ' data ' =>array (0=> Array (' uid ' = ' 0000008 '), 1=>array (' uid ' = ' 0000010 '), 2=>array (' uid ' = ' 0000009 '), 3=>array (' uid ' = ' 0000012 '), 4=>array (' uid ' = ' 0000013 '),), 3=>array (' Day ' = ' 2014-3-11 ',//Registration date ' data ' =>array (0 =>array (' uid ' = ' 0000015 '), 1=>array (' uid ' = ' 0000014 '), 2=>array (' uid ' = ' 0000025 '), 3=>array ( ' uid ' = ' 0000017 '), 4=>array (' uid ' = ' 0000018 '),));//login Log $array2 = Array (0=>array (' Day ' = ') 2014-3-8 ',//Login date ' Ge_data ' =>array (0=>array (' uid ' = ' 0000001 '), 1=>array (' uid ' = ' 0000002 '),3=> Array (' uid ' = ' 0000003')), 1=>array (' Day ' = ' 2014-3-9 ',//Login date ' ge_data ' =>array (' uid ' = ' 0000002 '), 1=>array (' UID ' = ' 0000007 '), 2=>array (' uid ' = ' 0000006 '),), 2=>array (' Day ' = ' 2014-3-11 ',//Login Date ' ge_data ' + = Array (0=>array (' uid ' = ' 0000001 '), 1=>array (' uid ' = ' 0000007 '), 2=>array (' uid ' = ' 0000008 '), 3 = >array (' uid ' = ' 0000012 '), 4=>array (' uid ' = ' 0000013 '), 5=>array (' uid ' = ' 0000003 '), 6=>array (' UID ' = ' 0000002 ')));
How can I get the following array:
Guys, help!
Reply to discussion (solution)
It's really hard ...
In a purely group, not impossible.
But the code is too targeted to use once in the future may not be useful
It is recommended that this stuff be stored in the database and then kneaded.
Look at your array and the requirements are not very clear
In a purely group, not impossible.
But the code is too targeted to use once in the future may not be useful
It is recommended that this stuff be stored in the database and then kneaded. That's what it reads from the database.
Looking at your array and the requirements are not very clear in fact is to calculate a next day retention number. For example, March 7 registered 4 people, check the March 8 which several people have logged in.
2014-03-09 3rd day The number of logins is 0 shouldn't it be number 11th? There were 7 people logged on that day.
2014-03-09 3rd day The number of logins is 0 shouldn't it be number 11th? There were 7 people logged on that day. Since March 9 The number of registrations is zero. So the number of people logged on on the nth day of March 9 is 0.
2014-03-09 3rd day The number of logins is 0 shouldn't it be number 11th? There were 7 people logged on that day. Since March 9 The number of registrations is zero. So the number of people logged on on the nth day of March 9 is 0.
And this logic, I mean, I'm messy.
2014-03-09 3rd day The number of logins is 0 shouldn't it be number 11th? There were 7 people logged on that day. Since March 9 The number of registrations is zero. So the number of people logged on on the nth day of March 9 is 0.
And this logic, I mean, I'm messy. March 9 The number of registrations is zero, so the UID for this day is empty, so in the log table is no matter what the next day of March 9 can not find the remaining number.
The account registered on the same day, on the following nth (n is natural number) day, also login account;
The final results to be achieved are as follows:
Don't sink the stick! There is a master who can help Ah!!!
It's not hard to spend time with complexity ... Working overtime again today .... No time for that.
You can loop it multiple times to get a value
Declare an empty array of results first
Then loop through the first array and save the date into
Loop the first second array in turn to determine the data you want to add and then put into the result array.
It's not hard to spend time with complexity ... Working overtime again today .... No time for that.
You can loop it multiple times to get a value
Declare an empty array of results first
Then loop through the first array and save the date into
Re-cycle the first second array in turn to determine the data you want to add up after the result array ah, I have tried to write this cycle, unfortunately Ah, can not write it!
It's not like multiplication formulas, look at that chart.
You can write this
Registration Information $array1 = Array (0=>array (' Day ' = ' 2014-3-7 ',//Registration date ' data ' =>array (0=>array (' uid ' = ' 0000001 '), 1 =>array (' uid ' = ' 0000002 '), 3=>array (' uid ' = ' 0000003 '), 4=>array (' uid ' = ' 0000004 '),)),1=> Array (' Day ' = ' 2014-3-8 ',//Registration date ' data ' =>array (0=>array (' uid ' = ' 0000005 '), 1=>array (' uid ' = " 0000007 '), 2=>array (' uid ' = ' 0000006 '),), 2=>array (' Day ' = ' 2014-3-10 ',//Registration date ' data ' =>array (0=> Array (' uid ' = ' 0000008 '), 1=>array (' uid ' = ' 0000010 '), 2=>array (' uid ' = ' 0000009 '), 3=>array (' uid ' = ' 0000012 '), 4=>array (' uid ' = ' 0000013 '),), 3=>array (' Day ' = ' 2014-3-11 ',//Registration date ' data ' =>array (0 =>array (' uid ' = ' 0000015 '), 1=>array (' uid ' = ' 0000014 '), 2=>array (' uid ' = ' 0000025 '), 3=>array ( ' uid ' = ' 0000017 '), 4=>array (' uid ' = ' 0000018 '),)); Login log $array2 = Array (0=>array (' Day ' = ' 2014-3-8 ',//Login date ' Ge_data ' =>array (0=>array (' uid ' = ' 0000001 ') ), 1=>array (' uid ' = ' 0000002 '), 3=>array (' uid ' = ' 0000003 ')), 1=>array (' Day ' = ' 2014-3-9 ',//Login date ' ge_data ' =>array (' uid ' = ' 0000002 '), 1=>array ( ' uid ' = ' 0000007 '), 2=>array (' uid ' = ' 0000006 '),), 2=>array (' Day ' = ' 2014-3-11 ',//Login date ' ge_data ' = >array (0=>array (' uid ' = ' 0000001 '), 1=>array (' uid ' = ' 0000007 '), 2=>array (' uid ' = ' 0000008 '), 3 =>array (' uid ' = ' 0000012 '), 4=>array (' uid ' = ' 0000013 '), 5=>array (' uid ' = ' 0000003 '), 6=>array ( ' uid ' = ' 0000002 ')); $res = Array ();//Read the Daily Registration record foreach ($array 1 as $r) {$day = $r [' Day ']; $res [$day] = Array (' Day ' + = $day, ' count ' = + count ($r [' data ')]; $d = Date (' Z ', Strtotime ($day)); For the same day, each user is registered with foreach ($r [' data '] as $US) {foreach ($array 2 as $t) {$rd = date (' Z ', Strtotime ($t [' Day ')]); Check which day he logged in to foreach ($t [' Ge_data '] as $u) {if ($US [' uid '] = = $u [' uid ']) $res [$day] [' Day_ '. $RD-$d) [] = $US [' uid ']; Save the login uid for easy Checking}}}}print_r ($res);
Array ([2014-3-7] = = Array ([day] + 2014-3-7 [Count] = 4 [day_1] =& Gt Array ([0] = 0000001 [1] = 0000002 [2] =& Gt 0000003) [Day_4] = = Array ([0] = 0000001 [1] = 0000002 [2] = 0000003) [day_2] = = Array ([0] = 0000002)) [2014-3-8] = = Array ([day] =& Gt 2014-3-8 [Count] = 3 [Day_1] = Array ([0] = 0000007 [1] = = 0000006) [Day_3] = = Array ([0 ] [0000007]) [2014-3-10] = Array ([Day] = 2014-3-10 [Count] => 5 [day_1] = = Array ([0] = 0000008 [1] = 000001 2 [2] = 0000013)) [2014-3-11] = = Array ([day] => ; 2014-3-11 [Count] = 5))
Unfortunately based on your data, you can't get the results of your example
I think you're mistaken.
Not like multiplication formulas. Look at that chart haha, it's kind of like.
My function is this, the start is the start date, such as 2014-1-1, the end is the end date, such as 2014-1-6, the query out 2014-1-1 to 2014-1-6 of the number of retained, see the first line, 1-1 new 100 people, +1 means 1-2 login How many people, + 2 indicates how many people are 1-3 logged in. Hey, this function is proposed by the operation, really let me headache ah this is!!!
Can write like this
Registration Information $array1 = Array (0=>array (' Day ' = ' 2014-3-7 ',//Registration date ' data ' =>array (0=>array (' uid ' = ' 0000001 '), 1 =>array (' uid ' = ' 0000002 '), 3=>array (' uid ' = ' 0000003 '), 4=>array (' uid ' = ' 0000004 '),)),1=> Array (' Day ' = ' 2014-3-8 ',//Registration date ' data ' =>array (0=>array (' uid ' = ' 0000005 '), 1=>array (' uid ' = " 0000007 '), 2=>array (' uid ' = ' 0000006 '),), 2=>array (' Day ' = ' 2014-3-10 ',//Registration date ' data ' =>array (0=> Array (' uid ' = ' 0000008 '), 1=>array (' uid ' = ' 0000010 '), 2=>array (' uid ' = ' 0000009 '), 3=>array (' uid ' = ' 0000012 '), 4=>array (' uid ' = ' 0000013 '),), 3=>array (' Day ' = ' 2014-3-11 ',//Registration date ' data ' =>array (0 =>array (' uid ' = ' 0000015 '), 1=>array (' uid ' = ' 0000014 '), 2=>array (' uid ' = ' 0000025 '), 3=>array ( ' uid ' = ' 0000017 '), 4=>array (' uid ' = ' 0000018 '),)); Login log $array2 = Array (0=>array (' Day ' = ' 2014-3-8 ',//Login date ' Ge_data ' =>array (0=>array (' uid ' = ' 0000001 ') ), 1=>array (' uid ' = ' 0000002 '), 3=>array (' uid ' = ' 0000003 ')), 1=>array (' Day ' = ' 2014-3-9 ',//Login date ' ge_data ' =>array (' uid ' = ' 0000002 '), 1=>array ( ' uid ' = ' 0000007 '), 2=>array (' uid ' = ' 0000006 '),), 2=>array (' Day ' = ' 2014-3-11 ',//Login date ' ge_data ' = >array (0=>array (' uid ' = ' 0000001 '), 1=>array (' uid ' = ' 0000007 '), 2=>array (' uid ' = ' 0000008 '), 3 =>array (' uid ' = ' 0000012 '), 4=>array (' uid ' = ' 0000013 '), 5=>array (' uid ' = ' 0000003 '), 6=>array ( ' uid ' = ' 0000002 ')); $res = Array ();//Read the Daily Registration record foreach ($array 1 as $r) {$day = $r [' Day ']; $res [$day] = Array (' Day ' + = $day, ' count ' = + count ($r [' data ')]; $d = Date (' Z ', Strtotime ($day)); For the same day, each user is registered with foreach ($r [' data '] as $US) {foreach ($array 2 as $t) {$rd = date (' Z ', Strtotime ($t [' Day ')]); Check which day he logged in to foreach ($t [' Ge_data '] as $u) {if ($US [' uid '] = = $u [' uid ']) $res [$day] [' Day_ '. $RD-$d) [] = $US [' uid ']; Save the login uid for easy Checking}}}}print_r ($res);
Array ([2014-3-7] = = Array ([day] + 2014-3-7 [Count] = 4 [day_1] =& Gt Array ([0] = 0000001 [1] = 0000002 [2] =& Gt 0000003) [Day_4] = = Array ([0] = 0000001 [1] = 0000002 [2] = 0000003) [day_2] = = Array ([0] = 0000002)) [2014-3-8] = = Array ([day] =& Gt 2014-3-8 [Count] = 3 [Day_1] = Array ([0] = 0000007 [1] = = 0000006) [Day_3] = = Array ([0 ] [0000007]) [2014-3-10] = Array ([Day] = 2014-3-10 [Count] => 5 [day_1] = = Array ([0] = 0000008 [1] = 000001 2 [2] = 0000013)) [2014-3-11] = = Array ([day] => ; 2014-3-11 [Count] = 5))
Unfortunately based on your data, you can't get the results of your example
You should be mistaken, thank you very much! Let me see! See for yourself! See if I can get the results I want!
Since it was read from the database: I think it's better to improve the SQL statement. When you're done, modify the array a little Shejinqiuyuan.
Since it was read from the database: I think it's better to improve the SQL statement. You're done. Then modify the array a bit Shejinqiuyuan this is read from the MONGODB data set! What if MySQL is ok! I don't have to bother!
Let me take a look at how everyone is analyzing this kind of problem.
Up the pose! It's all great gods.
Great gods! Is there any other trick? I'm all over this now!
Look at a bit dizzy, do not know you this array of content is casually written or real data, if it is real data I can not calculate how to count you this, except the next day of the pair.
If your number of logins is the number of logins, how is the third day 1?
Your login number = The number of people logged in, or the number of logins = number of log-in logs + number of registrations. Put the problem in a clear first.
Look at a bit dizzy, do not know you this array of content is casually written or real data, if it is real data I can not calculate how to count you this, except the next day of the pair.
If your number of logins is the number of logins, how is the third day 1?
Your login number = The number of people logged in, or the number of logins = number of log-in logs + number of registrations. Put the problem in a clear first.
The UID registered in March 7 is: 0000001,0000002,0000003,0000004
March 8 The login uid is: 0000001,0000002,0000003
March 9 The login uid is: 0000002,0000006,0000007
So for March 7, his second day, March 9, was logged on with a UID of only one 0000002
The following are all in turn ...
Look at a bit dizzy, do not know you this array of content is casually written or real data, if it is real data I can not calculate how to count you this, except the next day of the pair.
If your number of logins is the number of logins, how is the third day 1?
Your login number = The number of people logged in, or the number of logins = number of log-in logs + number of registrations. Put the problem in a clear first.
The UID registered in March 7 is: 0000001,0000002,0000003,0000004
March 8 The login uid is: 0000001,0000002,0000003
March 9 The login uid is: 0000002,0000006,0000007
So for March 7, his second day, March 9, was logged on with a UID of only one 0000002
The following are all in turn ... It's the third day, March 9.
So it should be.
[2014-3-7] = = Array ( [Day] = 2014-3-7 [Count] = 4 [Day_1] = = Array ( [0] = = 0000001 [1] = 0000002 [2] = 0000003 ) [day_4] = = Array ( [0] = = 0000001 [1] = 0000002 [2] = 0000003 ) [day_2] = = Array ( [0] = 0000002 ) )
That
3 days of the following day
Three days 1
Five days 3
And there is no fourth day of 2!
That's not right, as you say. March 8 The 4th day of the number of people logged on 1 should not be 2?
That's not right, as you say. March 8 The 4th day of the number of people logged on 1 should not be 2?
Oh, that's wrong.
So it should be.
[2014-3-7] = = Array ( [Day] = 2014-3-7 [Count] = 4 [Day_1] = = Array ( [0] = = 0000001 [1] = 0000002 [2] = 0000003 ) [day_4] = = Array ( [0] = = 0000001 [1] = 0000002 [2] = 0000003 ) [day_2] = = Array ( [0] = 0000002 ) )
That
3 days of the following day
Three days 1
Five days 3
And there is no fourth day of 2! Well, I'm wrong about this piece of writing.
The correct algorithm, will not get the wrong result
Basic algorithm I #15 have given, your job is just to optimize
correct algorithm, will not get the wrong result
Basic algorithm I #15 have given, your job is just optimization I was thinking, put your that array, and then process it into the array I want.
$array = Array (' 2014-3-7 ' = = Array (' Day ' = ' 2014-3-7 ', ' count ' = 4, ' day_1 ' = arr Ay (0 = 0000001, 1 = 0000002, 2 = 0000003), ' day_4 ' = arr Ay (0 = 0000001, 1 = 0000002, 2 = 0000003), ' day_3 ' = arr Ay (0 = 0000001, 1 = 0000002), ' day_2 ' = = Array (0 = 00000 ), ' day_5 ' = = Array (0 = 0000002)), ' 2014-3-8 ' = = Array (' DA Y ' = ' 2014-3-8 ', ' count ' = 3, ' day_4 ' = = Array (0 = 0000005, 1 = 00 00007), ' day_2 ' = = Array (0 = 0000005, 1 = 0000007, 2 = 00 00006), ' day_1 ' = = Array (0 = 0000007, 1 = 0000006), ' Day _3 ' = = Array ( 0 = 0000007, 1 = 0000006), ' 2014-3-10 ' = = Array (' Day ' = ' 2014-3-10 ' , ' count ' = 5, ' day_1 ' = = Array (0 = 0000008, 1 = 0000012, 2 = = 0000013), ' day_2 ' = = Array (0 = 0000008, 1 = 0000010, 2 = 0000012, 3 = 0000013), ' 2014-3-11 ' = = Array (' Day ' = ' 2014-3-11 ', ' Count ' = 5, ' day_1 ' = = Array (0 = 0000015, 1 = 0000025, 2 => ; 0000018)));
What can you think of?
$res [$day] [' Day_ '. $RD-$d) [] = $US [' uid '];
Change into
$res [$day] [' Day_ '. $rd-$d)]++;
Is it just a count?
What can you think of?
$res [$day] [' Day_ '. $RD-$d) [] = $US [' uid '];
Change into
$res [$day] [' Day_ '. $rd-$d)]++;
Is it just a count?
$d = Date (' Z ', Strtotime ($day)); What does this mean?
$d = Date (' Z ', Strtotime ($day));
In
$day is the date string provided by the array
Strtotime ($day) converting a date string to a Unix timestamp
Date (' Z ', Strtotime ($day)) Gets the day of the year
Hey! It's not the same as the end result I want!
$d = Date (' Z ', Strtotime ($day));
In
$day is the date string provided by the array
Strtotime ($day) converting a date string to a Unix timestamp
Date (' Z ', Strtotime ($day)) is the day of the year. Why do I change a set of data that will appear: [day_0] = = Array
(
[0] = 3001000
[1] = 3001726
[2] = 3001728
[3] = 3001733
[4] = 3001734
[5] = 3001735
[6] = 3001745
What's going on here?
The registration information ($array 1) and the login information ($array 2) Time (day) will appear day_0
Registration information ($array 1) and login information ($array 2) Time (day) is the same as day_0 how to avoid it? Where do I add a judgment?
What to avoid? The same day registration, the same day login, not very normal?
What to avoid? The same day registration, the same day login, not very normal?
What to avoid? The same day registration, the same day login, not very normal? But I just want to calculate his nth day login Ah!
What to avoid? The same day registration, the same day login, not very normal?
What to avoid? The same day registration, the same day login, not very normal? But I just want to calculate his nth day login Ah! Oh, I know, I don't take it.