I am building custom permissions system for different sections of a Laravel application.
I have an array of arrays and maybe there is a duplication in the section_id
value but with different permission
value.
for example i have section_id => 10
exists 3 times here with different 3 permission
.
[
0 => array:2 [▼
"section_id" => 10
"permission" => "B"
]
1 => array:2 [▼
"section_id" => 22
"permission" => "A"
]
2 => array:2 [▼
"section_id" => 10
"permission" => "A"
]
3 => array:2 [▼
"section_id" => 13
"permission" => "B"
]
4 => array:2 [▼
"section_id" => 18
"permission" => "B"
]
5 => array:2 [▼
"section_id" => 10
"permission" => "C"
]
]
Now I need to get only the highest permission level available in the array for the duplicated section section => 10
A,B and C are the permissions levels so the priority for A then B then C for the same section , the final result should be like this
[
0 => array:2 [▼
"section_id" => 10
"permission" => "A"
]
1 => array:2 [▼
"section_id" => 22
"permission" => "A"
]
2 => array:2 [▼
"section_id" => 13
"permission" => "B"
]
3 => array:2 [▼
"section_id" => 18
"permission" => "B"
]
]