This @var line should go directly to above the foreach, i.e., directly above the line where the variable is used for the first time.