I want to sort an array referencing the position of a property in another array for example.
$referenceArray = ['red', 'green', 'blue'];
$testArray = [obj1, obj2, obj3, obj4];
foreach($testArray as $object) {
if($object->colour === "red") {
// push to TOP of array
} elseif($object-color == "green") {
// push to MIDDLE of array
} elseif($object->color === "blue") {
// push to BOTTOM o array
}
}
Is this possible using a inbuilt php sort method? or can it only be done such as I have pseudo coded above.
Kind regards