Going on the super awesomely quick comments received i think i have 2 possible solutions...
(note: this is why it's called MVC not VMC or CVM lol)
example 1:
(add parent key name to child array):
$users=array(
'michael' => array(
'name' => 'michael', // add the parent arrays key name to the child array @see answer 2
'age' => '28',
'height' => '5\'9"',
)
);
function getUserName($array){
return $array['name'];
}
print getUserName($users['michael']); // 'michael'
example 2:
(pass whole array to function and pass key name as argument)
$users=array(
'michael' => array(
'age' => '28',
'height' => '5\'9"',
),
'adrienne' => array(
'age' => '26',
'height' => '5\'3"',
)
);
function getName($array,$array_key){
$keys = array_keys($array);
$key = array_search($array_key, $keys);
return $keys[$key];
}
print 'Name: '.getName($users,'michael');
but if your aware of the key name enough to provide it to the function getName() you could just provide the key name to the output...
$keyname = 'michael';
print 'name: '.$keyname;