Adding @almacbe fix to check if $key is array and do something
accordingly