Xml Sorting Problem
Posted 16 October 2012 - 11:00 AM
I am inserting the nodeValues into and array to use with CListView widget. The problem is that when I sort by price the sorting is not correct. I believe the problem is that sorting is done on a string basis and not on a numeric basis because it makes $3,000 > $10,000.
Any idea on how to solve this?
Thanks in advance!
Posted 17 October 2012 - 07:19 AM
// Remove any character that is not numeric or a decimal point $stripped = preg_replace('/[^0-9.]/', '', $original);
If you want to handle the whole array, $original can be replaced with an array of values and $stripped will be returned as an array.
I suggest you build up an additional column in your array (to hold the numeric values) and use one of the usort functions to perform a custom sort. You may need to cast the values in this column to doubles in order to assure numeric sorting, so don't use the values for anything other than the sort.
Posted 28 October 2013 - 08:45 AM
Most people will like to use simpleXML to convert XML to array, and here is some links to convert array into XML: