Basically I need to merge two arrays where the value 0 will take priority over 1.
I can’t find any native php function to do this, nor any function on google which surprised me (maybe i have been searching for the wrong things!), and I can’t think how to efficiently do it. Any suggestions?
For instance:
Array 1 Array 2
permission1 => 1 permission1 => 1
permission2 => 1 permission2 => 1
permission3 => 0 permission3 => 1
permission4 => 0 permission4 => 1
permission5 => 1
The resulting array would be.
permission1 => 1
permission2 => 1
permission3 => 0
permission4 => 0
permission5 => 1
As you may have guessed this is for a permissions system. Nothing denotes no permission, 0 means never, and 1 means has permission. I thought the best solution might involve adding the two together and seeing if you get 1 or 2, but I can’t think how to implement this.
I hope this question is clear, just ask for clarification if not. Thanks in advance for suggestions.
1 Answer