Created
May 30, 2014 18:53
-
-
Save vibhasbhingarde/faf415fbac1aa7c2bb59 to your computer and use it in GitHub Desktop.
Convert assoc array with id and title array to ci_dropdown array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function array_to_select($results, $value = 'id', $key = 'title', $add_blank=false) | |
{ | |
// Converts objects to arrays | |
if(is_object($results)) $results = get_object_vars($results); | |
$options = array(); | |
if(!empty($add_blank)) $options = array(null=>$add_blank); | |
// 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment