According to PHP (http://php.net/manual/en/…) if we compare an integer with a string, the string will always be returned as 0, so the first loop inside the foreach always returns true.
Quick solution is to change the if statement: