Y'know, it might be easier to have
$array[0]['name']='mary';
$array[0]['department']='accounts';
$array[1]['name']='mary';
$array[1]['department']='sales';
...
which could also be written as:
$array = (
array('name'=>'mary', 'department'=>'accounts'),
array('name'=>'mary', 'department'=>'sales'),
...
);
Then the search for mary's departments would go:
foreach($array as $person)
{ if($person['name']=='mary') echo $person['department'];
}
And the search for the people in sales would go
foreach($array as $person)
{ if($person['department']=='sales') echo $person['name'];
}