Your concept (The code you wrote above) would work, but it's kind of logically kludgy.
A better way to do it would be to do something like:
function _array($query) {
//Query or die with an error
$r=mysql_query($query) or die(mysql_error());
//Declaring an array may not be needed.
$a=array();
while($row = mysql_fetch_array($r)) {
//Add each item in the result set to the array.
$a[]=$row[name];
}
//return the array you just built.
return($a);
}
//Assign what array returns to the
$a = array($query);
//Now loop through the $a array to output each row of names from the table.
while($item = $a) {
echo $item."<br />";
}