aboutsummaryrefslogtreecommitdiffstats
path: root/include/text.php
diff options
context:
space:
mode:
authorzotlabs <mike@macgirvin.com>2018-02-01 17:17:23 -0800
committerzotlabs <mike@macgirvin.com>2018-02-01 17:17:23 -0800
commitcc0cd0b292f825d70a626c1ae5d46d0a43a825b9 (patch)
tree28120e3a5b6eed79affabb6de61b39fe5e2e090f /include/text.php
parentc92bb6176a79ef575c9a9b5dec8fde7034c6421c (diff)
downloadvolse-hubzilla-cc0cd0b292f825d70a626c1ae5d46d0a43a825b9.tar.gz
volse-hubzilla-cc0cd0b292f825d70a626c1ae5d46d0a43a825b9.tar.bz2
volse-hubzilla-cc0cd0b292f825d70a626c1ae5d46d0a43a825b9.zip
more generalisation of commonly used code constructs
Diffstat (limited to 'include/text.php')
-rw-r--r--include/text.php28
1 files changed, 28 insertions, 0 deletions
diff --git a/include/text.php b/include/text.php
index 8ec6ebace..10bbc751a 100644
--- a/include/text.php
+++ b/include/text.php
@@ -3261,3 +3261,31 @@ function purify_filename($s) {
return '';
return $s;
}
+
+
+/**
+ * @brief array_elm_to_str($arr,$elm,$delim = ',') extract unique individual elements from an array of arrays and return them as a string separated by a delimiter
+ *
+ * empty elements (evaluated after trim()) are ignored.
+ * @param $arr array
+ * @param $elm array key to extract from sub-array
+ * @param $delim string default ','
+ * @returns string
+ */
+
+function array_elm_to_str($arr,$elm,$delim = ',') {
+
+ $tmp = [];
+ if($arr && is_array($arr)) {
+ foreach($arr as $x) {
+ if(is_array($x) && array_key_exists($elm,$x)) {
+ $z = trim($x[$elm]);
+ if(($z) && (! in_array($z,$tmp))) {
+ $tmp[] = $z;
+ }
+ }
+ }
+ }
+ return implode($tmp,$delim);
+}
+