0

I'm trying to count frequency from input data.

Here is e.g input including Y value / X value / User Key

Y:5, X:3, User:A
Y:12, x:1, User:B
Y:66, X:2, User:A
Y:180, X:3, User:C
Y:328, X:4, User:D
Y:549, X:3, User:D
Y:765, X:2, User:A

Most important value is Y. I want to count each user's number of frequency each user have.

  • Y : 1~100
  • Y : 100~500
  • Y : 500~1000

I want this output of the counts of each user value like this :
(Each [value] will be used to insert to database)

[User Key] [Total counting] [1~100] [100~500] [500~1000]
User [A] have [3] data, [2] [0] [1]
User [B] have [1] data, [1] [0] [0]
User [C] have [1] data, [0] [1] [0]
User [D] have [2] data, [0] [1] [1]

I tried simply divide data to rows like this :

foreach ($input as $row) {
echo substr(strstr( $row, 'User:'), 5)
}

And I don't have any idea to count each Users. I'm still learning, and I would appreciate your help.

Jason
  • 1
  • first you need to group each user, then get ready to have 3 conditions, like your criteria above, and group them in another array, each iteration push it inside. then another foreach to present the tally – Kevin May 24 '21 at 07:16
  • @Kevin How can I group each user? Could you give me an example of how that works? – Jason May 25 '21 at 01:29
  • it will depend on how the input is supplied. how is that x y user given to you? like from a form? or from a text file formatted like that above? – Kevin May 25 '21 at 01:30
  • @Kevin X, Y, User information given like first form. (Y:5, X:3, User:A...) I'm struggling with converting and counting the username into a variable... (Each User [name]) – Jason May 25 '21 at 04:10

0 Answers0