Skip to content

Instantly share code, notes, and snippets.

@drmmr763
Last active December 15, 2015 02:59
Show Gist options
  • Save drmmr763/5191211 to your computer and use it in GitHub Desktop.
Save drmmr763/5191211 to your computer and use it in GitHub Desktop.
removes unmatched objects from an array of objects
<?php
public function filterResults($results)
{
$app = JFactory::getApplication();
$pattern = $app->input->get('filter_id');
// loop through results to remove unwanted results
for ($i = 0; $i <= count($results->entries)+1; $i++)
{
// loop through path way to find matches and remove if not found.
foreach ($results->entries[$i]->path_collection->entries as $result)
{
$matches = array();
// check for matches. if not found add index to array
if ($pattern === $result->id)
{
$matches[] = $i;
break 1;
}
}
// remove anything that didn't match
if (!in_array($i, $matches))
{
unset($results->entries[$i]);
}
}
// return the modified results array to the model
return $results;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment