I have a piece of code where a variable can either be an array or just a string.
if(!is_array($relation['display_name']))
{
// do something with $relation['display_name']
}
else
{
foreach($relation['display_name'] as $display_name)
{
// do the same with $display_name
}
}
This of course works – but it’s not very nice. And I would have to do it a lot of times. Is there a better way of doing this?
You can do it like this: