Lose all error logging and var_dumping.
Check it's an array, before acting on it as though it's an array
Strip those blasted slashes.