From 2bfa3de2202c5d40e7b54e307251f5741780ea0d Mon Sep 17 00:00:00 2001 From: zynode Date: Mon, 30 Jun 2008 20:01:50 +0000 Subject: [PATCH] Addressed Issue #4. Added option for sorting behavior type. git-svn-id: http://parsecsv-for-php.googlecode.com/svn/trunk@38 339761fc-0c37-0410-822d-8b8cac1f6a97 --- parsecsv.lib.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/parsecsv.lib.php b/parsecsv.lib.php index 50f6f70..252d416 100644 --- a/parsecsv.lib.php +++ b/parsecsv.lib.php @@ -94,6 +94,12 @@ class parseCSV { var $sort_by = null; var $sort_reverse = false; + # sort behavior passed to ksort/krsort functions + # regular = SORT_REGULAR + # numeric = SORT_NUMERIC + # string = SORT_STRING + var $sort_type = null; + # delimiter (comma) and enclosure (double quote) var $delimiter = ','; var $enclosure = '"'; @@ -473,7 +479,13 @@ class parseCSV { } $this->titles = $head; if ( !empty($this->sort_by) ) { - ( $this->sort_reverse ) ? krsort($rows) : ksort($rows) ; + $sort_type = SORT_REGULAR; + if ( $this->sort_type == 'numeric' ) { + $sort_type = SORT_NUMERIC; + } elseif ( $this->sort_type == 'string' ) { + $sort_type = SORT_STRING; + } + ( $this->sort_reverse ) ? krsort($rows, $sort_type) : ksort($rows, $sort_type) ; if ( $this->offset !== null || $this->limit !== null ) { $rows = array_slice($rows, ($this->offset === null ? 0 : $this->offset) , $this->limit, true); }