0

I have the following form and I need to check for unchecked boxes

<input type="checkbox" name="permission[]" value="user.create">Create</input>
<input type="checkbox" name="permission[]" value="user.update">Update</input>
<input type="checkbox" name="permission[]" value="user.delete">Delete</input>
<input type="checkbox" name="permission[]" value="user.read">Read</input>
<input type="submit" name="submit" value="Submit"/>

The way that it is right now It gives me an array like permission['user.create'.'user.read'.'user.delete']. What I need is another array that says for example unSelected['user.update']

Update: I cant use hidden fields because all the values are supposed to be stored in an array.

George Kagan
  • 5,913
  • 8
  • 46
  • 50
Mntfr
  • 483
  • 6
  • 20
  • No It is just pure php – Mntfr Nov 02 '16 at 16:48
  • I am developing a permissions system with laravel however the client wants it so that he can customize which permissions the role has, and he wants to be able to select them in comboboxes so I can alredy give new permissions with the form above but I cant remove them because I dont know how to search for unselected comboboxes – Mntfr Nov 02 '16 at 16:55
  • Better dupe showing array usage: http://stackoverflow.com/questions/33292526/setting-value-of-unchecked-checkbox-php/33292573#33292573 – AbraCadaver Nov 02 '16 at 16:57
  • Well you can have one pre-defined main array that contains all the allowed values and when you submit the form you have the ones that are checked so now you can use array_diff to segregate the unchecked ones. – Just_Do_It Nov 02 '16 at 18:10

2 Answers2

0

Well you can have one pre-defined main array that contains all the allowed values and when you submit the form you have the ones that are checked so now you can use array_diff to segregate the unchecked ones.

<?php
$a = array('a','b','c','d','e'); //main array

$b = array('a','c','e'); //submitted array

$c = array_diff($a, $b);

print_r($c); //will give Array ( [1] => b [3] => d )

?>
Just_Do_It
  • 821
  • 7
  • 20
0

Try this:

$unSelected= array_diff(array('user.create', 'user.update', 'user.delete', 'user.read'), $permission);
evalarezo
  • 1,134
  • 7
  • 13