summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--it.class9
-rwxr-xr-xtests/it.t4
2 files changed, 12 insertions, 1 deletions
diff --git a/it.class b/it.class
index 073b2bf..b097e60 100644
--- a/it.class
+++ b/it.class
@@ -1030,5 +1030,12 @@ static function json_decode($json)
return ($data = json_decode($json)) === null && $json != 'null' ? it::error(array('title' => "invalid json", 'body' => $json)) : $data;
}
+static function sort($array, $mode = "")
+{
+ $func = it::replace(array('n' => ""), count_chars($mode, 3)) . "sort"; # count_chars sorts flags
+ $func($array, it::match('n', $mode) ? SORT_NUMERIC : 0);
+
+ return $array;
+}
+
}
-?>
diff --git a/tests/it.t b/tests/it.t
index 10c4d0e..33a6c13 100755
--- a/tests/it.t
+++ b/tests/it.t
@@ -393,3 +393,7 @@ is(it::any2utf8(array(utf8_decode('Müller') => utf8_decode('Müller'))), array(
foreach (array($dummy, false, true, null, 1, "a", "Ä", "/", array()) as $var)
is(it::json_decode(it::json_encode($var)), $var);
+
+is(it::sort(array("2!","19!","1!")), array("1!", "19!", "2!"));
+is(it::sort(array("2!","19!","1!"), "r"), array("2!", "19!", "1!"));
+is(it::sort(array("2!","19!","1!"), "rn"), array("19!", "2!", "1!"));