I have an object and store it in an array. However, when outputting the names from the object, I want to sort them by 'is_main'. Thereby 'is_main' with the value 1 should always be in the first place and then 'is_main' with the value 0. Here is the Object
array(2){
[
1
]=> object(stdClass)#3729 (22){
[
"id_teacher"
]=> string(1)"2"[
"firstname"
]=> string(6)"John"[
"lastname"
]=> string(8)"Doe"[
"is_main"
]=> string(1)"0"
}[
2
]=> object(stdClass)#3723 (22){
[
"id_teacher"
]=> string(1)"2"[
"firstname"
]=> string(6)"John"[
"lastname"
]=> string(8)"Brown"[
"is_main"
]=> string(1)"1"
}
}
And my PHP Code:
$storage = array();
foreach($data->class_teacher_arr[$item->id_class] as $reference) {
$storage[] = $reference->firstname . ' ' . $reference->lastname . ' ' . $reference->is_main;
}
echo implode('<br/>', $storage);
I hope that someone can help me by this problem.
usort()function to sort by a property.