Last active
December 18, 2015 03:49
-
-
Save tamboer/5721010 to your computer and use it in GitHub Desktop.
php array add groups to selection and remove groups
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| public function addGroupToSelection($groups) { | |
| if (count($groups) > 0) | |
| foreach ($groups as $group) | |
| foreach ($group as $item) | |
| if (!$this->isInGroup($item, $this->main_selection)) | |
| $this->main_selection[] = $item; | |
| } | |
| public function removeGroupFromSelection($groups) { | |
| if (count($groups) > 0) | |
| foreach ($groups as $group) | |
| $arr = array_diff($this->main_selection, $group); | |
| $this->main_selection = $arr; | |
| } | |
| protected function isInGroup($id, $group) { | |
| if (in_array($id, $group)) | |
| return $this->is_in_group = true; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment