Fixing Invalid argument supplied for foreach().