I basically have a PHP function that is in a giant foreach statement and needs to be in that foreach because it uses values from the loop.
foreach ($x as $y) {
...
function sortq($a, $b){
if ((int)$a->id == (int)$b->id) {
return 0;
}
return ((int)$a->id < (int)$b->id) ? -1 : 1;
}
usort($sort, 'sortq');
...
}
How do I strip this function out into a generic class or method so that I can call it any number of times? I attempted the 'class' route but was then redeclaring classes in the foreach loop :D
Please help! Many thanks