aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMaZderMind2016-12-18 13:31:34 +0100
committerMaZderMind2016-12-18 13:31:34 +0100
commit35e7a2b2adad42b077de60d1566c22da62edeb77 (patch)
treebe89253bbf80fc8383311137761a8a472e5d8b40 /lib
parent46634852dc1af3fe53136a2d48bc3157e3bbad62 (diff)
move upcoming & current logic from javascript/ajax into php
Diffstat (limited to 'lib')
-rw-r--r--lib/helper.php31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/helper.php b/lib/helper.php
index df7f329..1925382 100644
--- a/lib/helper.php
+++ b/lib/helper.php
@@ -114,3 +114,34 @@ function url_params()
return '';
}
+
+/**
+ * returns the fielst element matching $predicate or null, if none matched.
+ * $predicate is a callable that receives one array value at a time and can
+ * return a bool'ish value
+ */
+function array_filter_first($array, $predicate)
+{
+ foreach ($array as $value) {
+ if( $predicate($value) ) {
+ return $value;
+ }
+ }
+
+ return null;
+}
+/**
+ * returns the fielst element matching $predicate or null, if none matched.
+ * $predicate is a callable that receives one array value at a time and can
+ * return a bool'ish value
+ */
+function array_filter_last($array, $predicate)
+{
+ foreach (array_reverse($array) as $value) {
+ if( $predicate($value) ) {
+ return $value;
+ }
+ }
+
+ return null;
+}