One to many PHP allocation for users

One to many PHP allocation for users
I have a business requirement that there are two types of users (the number of users in the second type is far more than that in the first type), and then they need to match according to their preferences and regions.
For example, Class A users can select multiple preferences and multiple cities, such as userA1 and userA2 in the following example,
Examples of Class A users are as follows:

{
    label:'userA1', 
    type:1,
    like:['1', '4', '11'],
    like2:['3','14','15'],
    city:['1','2']
},
{
    label:'userA2', 
    type:1,
    like:['1', '11'],
    like2:['3','13'],
    city:['2', '3']
},

Class B users: they can only select single preference and city, such as userB1, userB2,
Examples of Category B users are as follows:

{
    label:'userB1',
    type:2,
    like:"1",
    like2:"3"
    city:"1"
},
{
    label:'userB2',
    type:2,
    like:"4",
    like2:"7"
    city:"6"
},

When allocating, they need to match according to their preferences. The matching rules are:

  1. Both users must match the city field;
  2. Priority should be given to both parties to match the like field. If the like field of a class B user does not match that of a class A user, the like field of a class A user should be used for matching. If it does not match, it will be empty;
  3. Each Class A user cannot match more than 5 Class B users at most. If there are too many Class B users, and all matching Class A users match 5, continue to allocate in Steps 1 and 2 until all Class B users are allocated.
    A request of my little partner was slightly fuzzed. Because my main language is Js, PHP doesn’t know much about it, so he rejected several solutions.
    So I had the audacity to come to the community and ask if there was a big guy who could give me some ideas
    The difficulty he found was that the three attributes of Class A users were all multi selected.

one cannot give priority to both; that just makes them equal again. :stuck_out_tongue:

I dont… really understand the goal here.

What is allocating, what is the desired outcome?

So, you’re asking about memory allocation.

Why is this an issue? You haven’t explained what you are attempting to do here.

Sorry, when I copied and pasted the problem, I missed a paragraph. Later: a request from my little partner was slightly blurred. Because my main language is Js, PHP doesn’t know much about it, so he rejected several solutions.
So I had the audacity to come to the community and ask if there was a big guy who could give me some ideas
The difficulty he found was that the three attributes of Class A users were all multi selected.
I said to ask him to group Class A users according to like, add count attribute and sort by it, and then use Class B users to allocate one by one. If the allocation is successful, count++the corresponding Class A users and run all Class B users.
But he said no, and finally he couldn’t handle the third rule. At most, he could do unlimited allocation, but I didn’t get to the point of why not. Maybe the programming idea of Js is a little different from that of PHP
It may be that a user A selects all the preferences and then a giant appears???

Maybe if you could show the desired output, that might make it clearer. I’m not really sure what you mean by “allocating” in this context. I’m not really sure what you mean by any of it, in truth, but maybe seeing the expected output might make that clearer.

2 Likes