I have a foreach that creates a url for each item based on the $mainCat and $subCat of course I know that there will be duplicates due to some items being in the same categories.
Is there away that I can just return one url of each $mainCat & $subCat properties?
foreach ($detailsFunction as $main)
{
$ld = array('listingId' => $main['listingId']);
foreach($ld as $id)
{
$mainlisting = $main['listingId'];
$mainCat = strtolower($main['mainCat']);
$subCatO = strtolower($main['subCat']);
$subCat = str_replace(" ", "-", $subCatO);
$structure = base_url().'listings/'.$mainCat.'/'.$subCat;
$url[] = $structure;
}
}
return $url;
var_dump($url);
}
If I’m understanding your question you want to produce an array without duplicate values?
You could test if the
$structureis in$urlbefore you add it:or use
array_uniqueafter your loops are done: