Unfortunately, no.
You could do something like this:
function getData($id) {
// mysql query
return mysql_fetch_array($result);
}
foreach(getData("your_input_query") as $key=>$value){
echo $value;
}
And then you could use a switch or if/else statements to only perform other functions on the returned data if they equal a certain value (in this case, if $key == 'name').
In short, it's much easier just to set that temporary variable and access it that way.