Right, so go back to my example; the point of using [man]foreach[/man]($to as $data) is that the foreach() construct will place each array entry into $data after each iteration. It's basically a while() loop that loops through all array indexes one-by-one.
Since you still used $to inside the foreach() loop, though, you basically ignored the whole point of the foreach() statement and accessed the array directly. Instead, you should be using $data (without any array index, since $data will reference the contents of the array one-by-one, and the contents are objects).