If you use> = PHP 5.3, you can try something like this. It will run the element code if it is singular or implicit over all elements of the array, if the array.
function call($element, $func) {
if (is_array($element)) {
foreach($element as $value) {
$func($value);
}
} else {
$func($element);
}
}
call($relation['display_name'], function($display_name) {
});
CodePad .
source
share