I have an array that can be many levels deep for example
'For Sale' => array(
'Baby & Kids Stuff' => array(
'Car Seats & Baby Carriers',
),
),
'For Rent' => array(
'Other' => array(
'Baby Clothes',
),
'Prices' => 'hhhhhh',
),
What I am trying to do is search both the array keys and values to match a string, I have come up with this so far but it isn't working...
// validate a category
public function isValid($category, $data = false) {
if(!$data) {
$data = $this->data;
}
foreach($data as $var => $val) {
if($var === $category) {
return true;
} elseif(is_array($val)) {
$this->isValid($category, $data[$var]);
} elseif($val === $category) {
return true;
}
}
}
I don't know what I am doing wrong, many thanks.