Last active
December 15, 2015 02:59
-
-
Save drmmr763/5191211 to your computer and use it in GitHub Desktop.
removes unmatched objects from an array of objects
This file contains 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 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