I\'m trying to do some kind of function that will find (in the following array) the object with the id of 2, and move it to the top of the array. Here\'s the original array:
function customShift($array, $id){
foreach($array as $key => $val){ // loop all elements
if($val->id == $id){ // check for id $id
unset($array[$key]); // unset the $array with id $id
array_unshift($array, $val); // unshift the array with $val to push in the beginning of array
return $array; // return new $array
}
}
}
print_r(customShift($data, 2));