I'd start with the For Each line missing the rest of the vars...

For each $item in $array
...

Next