[eluser]Phil Sturgeon[/eluser]
Why would you pass in an array? You are over complicating this a great deal.
Code:
function array_to_select($results, $value = 'id', $key = 'title')
{
// Converts objects to arrays
if(is_object($results)) $results = get_object_vars($results);
$options = array();
// Will only run if results is an array, not a string, int, etc.
if(!is_array($results))
{
foreach($results as $result)
{
// Get the two rows specified
$options[$result[$value]] = $result[$key];
}
}
return $options;
}
You can see if I dont provide either of the last two arguments it defaults to id and title. These are just standard field names so you may wish to change that or remove the default value if you plan to always set them in the function call.