My array $user->profile_tags is multi-dimensional. It might be created thus:
$user->profile_tags = array(array('Whisky', 0), array('Vodka', 0), array('Gin','Gin'))
For someone who only liked Gin. I need to search the array for 'Gin' but only the values, not the keys. Using in_array("Vodka", $user->profile_tags) will return TRUE here when I need it to return false.
I have tried this function:
<?
// Function for looking for a value in a multi-dimensional array
function in_multi_array($value, $array)
{
foreach ($array as $key => $item)
{
// Item is not an array
if (!is_array($item))
{
// Is this item our value?
if ($item == $value) return true;
}
// Item is an array
else
{
// See if the array name matches our value
//if ($key == $value) return true;
// See if this array matches our value
if (in_array($value, $item)) return true;
// Search this array
else if (in_multi_array($value, $item)) return true;
}
}
// Couldn't find the value in array
return false;
}
?>
But for some reason it does not work at all.