Fix warning - Invalid argument supplied for foreach