PHP : result to array function
if (!function_exists('result_to_array')) {
function result_to_array($result_set=array(), $value_feild='', $label_field='')
{
$_ci = get_instance();
$option = [];
foreach ((array)$result_set as $key => $value) {
if(is_array($label_field)){
if(count($label_field) > 0){
$lbltext = array();
foreach ($label_field as $lblval) {
$lbltext[] = $value->$lblval;
}
$lbl = implode(' - ',$lbltext);
}else{
$lbl = $value->$label_field;
}
}else{
$lbl = $value->$label_field;
}
$option[$value->$value_feild] = $lbl;
}
return $option;
}
}
No comments:
Post a Comment