more generalisation of commonly used code constructs

This commit is contained in:
zotlabs
2018-02-01 17:17:23 -08:00
parent c92bb6176a
commit cc0cd0b292
2 changed files with 29 additions and 15 deletions

View File

@@ -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);
}