Skip to content

Instantly share code, notes, and snippets.

@tamboer
Last active December 18, 2015 03:49
Show Gist options
  • Select an option

  • Save tamboer/5721010 to your computer and use it in GitHub Desktop.

Select an option

Save tamboer/5721010 to your computer and use it in GitHub Desktop.
php array add groups to selection and remove groups
<?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