add key value pair to existing array
foreach($users as $index => $user) {
$users[$index]['age'] = getUserAge($user['userid']);
}
foreach($users as &$user){
$age = getUserAge($user['userid']);
$user['age'] = $age;
}
Compact Version:
foreach($users as &$user){
$user['age'] = getUserAge($user['userid']);
}
Note the ampersand before the array variable name meaning the variable is passed by reference, and so can be modified. See the docs for more info.