Re: sorting, was: Version 3.0 now available!
Brought to you by:
bs_php,
nigelswinson
From: Nigel S. <nig...@us...> - 2002-05-13 20:47:10
|
> What I'll try to do is to make doc order the default output, but there may > still be occasions where sorting the data by some other criteria is useful. Ok the default order for the results is now doc order. Sorting by other means probably isn't too difficult anyway, as you can use the usort() function that takes a callback of two elements that you can then write your own function to compare elements with. So you would do something like this (haven't tested this...): $XPathObj = new XPath; function cmp($a, $b) { global $XPathObj; $sA = $XPathObj->getData($a.'/SomewhereElse'); $sB = $XPathObj->getData($b.'/SomewhereElse'); return (strcmp($sA, $sB)); } $aPaths = $XPathObj->evaluate('something or other'); usort($aPaths, "cmp"); Nigel |