From: martinlanghoff <martinlanghoff>
Date: Wed, 19 Sep 2007 07:01:53 +0000 (+0000)
Subject: datalib: Introducing sql_intarray_to_in()
X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=41883f79ca5ac0fed49b919b087d110642f5c13e;p=moodle.git

datalib: Introducing sql_intarray_to_in()

Trivial function to turn an array of ints into a string
usable in an IN sql clause.
---

diff --git a/lib/datalib.php b/lib/datalib.php
index 6cadd7241a..03d148f753 100644
--- a/lib/datalib.php
+++ b/lib/datalib.php
@@ -1770,5 +1770,21 @@ function get_creatable_categories() {
     return $creatablecats;
 }
 
+/**
+ * Turn an array of ints into a string usable in an IN sql clause...
+ *
+ **/
+function sql_intarray_to_in($array) {
+
+    $na = array();
+    $c = count($array);
+    for ($n=0;$n<$c;$n++) {
+        if (isset($array[$n]) && is_int($array[$n])) {
+            $na[] = $array[$n];
+        }
+    }
+    return join(',',$array);
+}
+
 // vim:autoindent:expandtab:shiftwidth=4:tabstop=4:tw=140:
 ?>