]> git.mjollnir.org Git - moodle.git/commitdiff
datalib: Introducing sql_intarray_to_in()
authormartinlanghoff <martinlanghoff>
Wed, 19 Sep 2007 07:01:53 +0000 (07:01 +0000)
committermartinlanghoff <martinlanghoff>
Wed, 19 Sep 2007 07:01:53 +0000 (07:01 +0000)
Trivial function to turn an array of ints into a string
usable in an IN sql clause.

lib/datalib.php

index 6cadd7241ae5c0cb2600860d23dde2d896833f03..03d148f753fc9c3b0b40487353ec502bb0f3ec21 100644 (file)
@@ -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:
 ?>