I am trying to check if I have the $subCat value in the array then don’t add it. I should end up with one of each $subCat but when I dump $details I am still getting the full array. Why is this?
foreach ($detailsFunction as $main)
{
$mainlisting = $main['listingId'];
$mainCat = strtolower($main['mainCat']);
$subCatO = strtolower($main['subCat']);
$subCat = str_replace(" ", "-", $subCatO);
if(isset($subCat) && $subCat == $subCat)
{
$details[] = array('url' => base_url().'listings/'.$mainCat.'/'.$subCat,
'mainCat' => $main['mainCat'],
'subCat' => $main['subCat']
);
}
}
Are you concerned with keeping the keys of
$detailsnumeric? If not You could add each item with$subCatas its key, and check if the key exists before adding it: