However, I think the code you posted does not work. You reset $list to nothing before it is processed by foreach. I changed the code by adding a separate variable $listout and now it works:
Code: Select all
echo listFilter(get("list_recentlocations"), 'exists("{@Item}")', <crlf>)
/**
* List Filter
*
* @param {list} $list list of tokens
* @param {expression} $filter expression which returns {bool} on evaluation
* placeholder: {@Item}
* @param {string} [$separator='|'] list separator
* @param {flag} $flag + s : escape single quote (') for each item
*
* @return {list} filtered list of tokens
*/
function listFilter($list, $filter, $separator = '|', $flag = '') {
$listout = "";
foreach($item, $list, $separator) {
if (strpos($flag, 's') >= 0) {
$item = replace($item, "'", "''");
}
$expr = replace($filter, '{@Item}', $item, 1);
if (eval($expr)) {
$listout = $listout . $item . $separator;
}
}
return trim($listout, $separator, 'R');
}