I create a form to do the following:
- Print a table of users and permissions, pulling from MySQL. Each permission of the user has a flag, and each of them lacks a flag.
- Allow the administrator to check and uncheck the boxes to grant or remove permissions.
- When the form is submitted, show the confirmation page with ONLY users whose permissions will be changed, highlighting specific changes.
- When the changes are confirmed, modify the database accordingly.
To do this, I create two arrays of user permissions: one according to what the database shows, and one according to what the form shows.
If the user does not have permission in MySQL, it will be displayed as 0. If they do not have permission in the form submission, it simply will not exist.
Here are two simple examples of arrays:
Database array
[User1] => Array ([public] => 1
[private] => 1
[secret] => 1
)
[User2] => Array ([public] => 1
[private] => 0
[secret] => 0
)
Array of form submission (canceling the "secret" from User1 and providing it to user2)
[User1] => Array ([public] => 1
[private] => 1
)
[User2] => Array ([public] => 1
[secret] => 1
)
Question
How can I elegantly combine these two arrays to create an array of "changes", for example:
- Users with the same permissions are omitted in both.
- - , - 0, 1.
- 0, , 1,
, :
[User1] => Array ([public] => 1
[private] => 1
[secret] => 0
)
[User2] => Array ([public] => 1
[private] => 0
[secret] => 1
)
- array_merge() , , , , . , .
- foreach() , , ,
UPDATE
! . , - , . back back script , AJAX- . , . , .