$status = array (); $status[1] = 'Foo'; $status[2] = 'Bar'; $status[3] = 'Baz'; $status[4] = 'Spaz'; $status[5] = 'Hello'; $status[6] = 'World'; $var = 'status'; create_radio_options ($var,2,5,$form[$var],$$var, true); /* outputs: Bar Baz Spaz Hello */ function create_radio_options ($name, $start, $end, $selected, $items, $echo = false) { $buttons = ''; for ($i = $start; $i <= $end; $i++) $buttons .= sprintf('%s'."\n", $name, $i, selected($i, $selected), $items[$i]); if(!$echo) return $buttons; echo $buttons; }