Jump to content

AlecGuinn

New Members
  • Posts

    4
  • Joined

  • Last visited

Everything posted by AlecGuinn

  1. Thanks for your anwser ! I dont understand what this two lines should do. I would like to keep keys (item1,item2...) but I still have non unique values. Like the 2 first combinations i still have 2 A and 3 B and 2 A and 2 B. A,B,C are users. Each users should have only 1 item. [0] => Array ( [0] => A [1] => A [2] => B ) [1] => Array ( [0] => A [1] => A [2] => E ) I would like to have something like that: [0] => Array ( [item1] => A [item2] => C [item3] => B ) [1] => Array ( [item1] => B [item2] => A [item3] => D )
  2. Hey ! I have found this get_combinations function which kinda seems to do what i need. BUT I need the results to only have unique values "[item1] => A [item2] => C [item3] => B" is OK, but "[item1] => A [item2] => A [item3] => B" is NOT. How can i get rid of this non unique combination ? Thanks function get_combinations($arrays) { $result = array(array()); foreach ($arrays as $property => $property_values) { $tmp = array(); foreach ($result as $result_item) { foreach ($property_values as $property_value) { $tmp[] = array_merge($result_item, array($property => $property_value)); } } $result = $tmp; } return $result; } $combinations = get_combinations( array( 'item1' => array('A', 'B'), 'item2' => array('A', 'D', 'E', 'F'), 'item3' => array('B', 'E', 'F'), ) ); var_dump($combinations); array(24) { [0]=> array(3) { ["item1"]=> string(1) "A" ["item2"]=> string(1) "A" ["item3"]=> string(1) "B" } [1]=> array(3) { ["item1"]=> string(1) "A" ["item2"]=> string(1) "A" ["item3"]=> string(1) "E" } [2]=> array(3) { ["item1"]=> string(1) "A" ["item2"]=> string(1) "A" ["item3"]=> string(1) "F" } [3]=> array(3) { ["item1"]=> string(1) "A" ["item2"]=> string(1) "D" ["item3"]=> string(1) "B" } [4]=> array(3) { ["item1"]=> string(1) "A" ["item2"]=> string(1) "D" ["item3"]=> string(1) "E" } [5]=> array(3) { ["item1"]=> string(1) "A" ["item2"]=> string(1) "D" ["item3"]=> string(1) "F" } [6]=> array(3) { ["item1"]=> string(1) "A" ["item2"]=> string(1) "E" ["item3"]=> string(1) "B" } [7]=> array(3) { ["item1"]=> string(1) "A" ["item2"]=> string(1) "E" ["item3"]=> string(1) "E" } [8]=> array(3) { ["item1"]=> string(1) "A" ["item2"]=> string(1) "E" ["item3"]=> string(1) "F" } [9]=> array(3) { ["item1"]=> string(1) "A" ["item2"]=> string(1) "F" ["item3"]=> string(1) "B" } [10]=> array(3) { ["item1"]=> string(1) "A" ["item2"]=> string(1) "F" ["item3"]=> string(1) "E" } [11]=> array(3) { ["item1"]=> string(1) "A" ["item2"]=> string(1) "F" ["item3"]=> string(1) "F" } [12]=> array(3) { ["item1"]=> string(1) "B" ["item2"]=> string(1) "A" ["item3"]=> string(1) "B" } [13]=> array(3) { ["item1"]=> string(1) "B" ["item2"]=> string(1) "A" ["item3"]=> string(1) "E" } [14]=> array(3) { ["item1"]=> string(1) "B" ["item2"]=> string(1) "A" ["item3"]=> string(1) "F" } [15]=> array(3) { ["item1"]=> string(1) "B" ["item2"]=> string(1) "D" ["item3"]=> string(1) "B" } [16]=> array(3) { ["item1"]=> string(1) "B" ["item2"]=> string(1) "D" ["item3"]=> string(1) "E" } [17]=> array(3) { ["item1"]=> string(1) "B" ["item2"]=> string(1) "D" ["item3"]=> string(1) "F" } [18]=> array(3) { ["item1"]=> string(1) "B" ["item2"]=> string(1) "E" ["item3"]=> string(1) "B" } [19]=> array(3) { ["item1"]=> string(1) "B" ["item2"]=> string(1) "E" ["item3"]=> string(1) "E" } [20]=> array(3) { ["item1"]=> string(1) "B" ["item2"]=> string(1) "E" ["item3"]=> string(1) "F" } [21]=> array(3) { ["item1"]=> string(1) "B" ["item2"]=> string(1) "F" ["item3"]=> string(1) "B" } [22]=> array(3) { ["item1"]=> string(1) "B" ["item2"]=> string(1) "F" ["item3"]=> string(1) "E" } [23]=> array(3) { ["item1"]=> string(1) "B" ["item2"]=> string(1) "F" ["item3"]=> string(1) "F" } } int(1)
  3. Its more about a coding problem on how i can put users on the good role. Im a php newby and i cant find a logic, a way to sort this the good way. $in_team = array(); foreach ($roles_array as $role_id => $role) { foreach ($users_roles[$role_id] as $user_id => $score) { if (!in_array($user_id, $in_team)) { $final_array[$role_id] = $user_id; $in_team[] = $user_id; break; } } } I end up with this: // Keys are role_id, values are user_id $final_array = Array ( [2] => 1 [10] => 613 [1] => 751 [6] => 709 [4] => 649 [3] => 797 [5] => 594 [8] => 445 ) But for exemple, i have lost role 7 which is a role with importance. The priority is to have users in roles with the highest importance and in this roles having the user with the lowest score (the ones on the top of the Users arrays), with 1 user by role. // Role list with keys as role_id, order by importance DESC $roles_array = Array ( [2] => Array ( [role_id] => 2 [importance] => 9 ) [10] => Array ( [role_id] => 10 [importance] => 9 ) [1] => Array ( [role_id] => 1 [importance] => 8 ) [6] => Array ( [role_id] => 6 [importance] => 8 ) [4] => Array ( [role_id] => 4 [importance] => 7 ) [7] => Array ( [role_id] => 7 [importance] => 7 ) [3] => Array ( [role_id] => 3 [importance] => 0 ) [5] => Array ( [role_id] => 5 [importance] => 0 ) [8] => Array ( [role_id] => 8 [importance] => 0 ) [9] => Array ( [role_id] => 9 [importance] => 0 ) ) // Users array by roles with role_id as key and a list of user_id (user_id as key) sort by user "score" the first one having the priority on the role. $users_roles = Array ( [2] => Array ( [1] => -10403083 [649] => -10103685 [445] => -10103190 [613] => -10103162 [594] => -10003838 ) [10] => Array ( [1] => -10101899 [613] => -10101799 [649] => -10101599 [445] => -10101299 ) [1] => Array ( [751] => -9106772 [613] => -9106679 [709] => -9106281 [1] => -9106179 [445] => -9106175 [594] => -9106087 [797] => -9006662 ) [6] => Array ( [751] => -9106772 [613] => -9106679 [709] => -9106281 [1] => -9106179 [445] => -9106175 [594] => -9106087 [797] => -9006662 ) [4] => Array ( [613] => -8205090 [649] => -8105661 [709] => -8105270 [1] => -8105188 [751] => -8104676 ) [7] => Array ( [613] => -8205090 [649] => -8105661 [709] => -8105270 [1] => -8105188 [751] => -8104676 ) [3] => Array ( [797] => -1506653 [751] => -1106899 [1] => -1106894 [649] => -1106793 [613] => -1106299 [709] => -1105790 [594] => -1006679 ) [5] => Array ( [594] => -1510886 [797] => -1210750 [613] => -1111984 [751] => -1111673 [1] => -1111193 [709] => -1110979 [445] => -1108879 [649] => -1108683 ) [8] => Array ( [594] => -1510886 [797] => -1210750 [613] => -1111984 [751] => -1111673 [1] => -1111193 [709] => -1110979 [445] => -1108879 [649] => -1108683 ) [9] => Array ( [594] => -1510886 [797] => -1210750 [613] => -1111984 [751] => -1111673 [1] => -1111193 [709] => -1110979 [445] => -1108879 [649] => -1108683 ) ) Thanks you
  4. Hey, I am struggling to find a way to code an idea. I have a list of 10 peoples (possibly less) and i'd like to give them roles on a team. In this team, roles have differents importances. I have a roles array sort by importance. For each roles i have an array of people who can achieve this role base on a value (The lowest value having the highest priority) . Everyone CANT do every roles. I'd like to have the best team composition base on the role importance and the users roles values. Any help ? Ty
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.