$arr[] = array(...,'id'=1,'prev'=>2,'next'=>null);
$arr[] = array(...,'id'=2,'prev'=>3..,'next'=>1);
$arr[] = array(...,'id'=3,'prev'=>4,'next'=>2);
..
The order of each record can be arbitary.
How to sort this kind of array so that record with prev‘s value null is first,and the one with null next is last?
I believe the built in usort will work nicely for the data structure you described.
edit: This doesn’t work correctly. Please un-accept so I can delete it.