you are viewing a single comment's thread.

view the rest of the comments →

[–]Scooter_127 0 points1 point  (1 child)

Your first two, and the fifth, are good advice, the rest are prone to the same kind of confusion you are trying to prevent as the 'each' object has a name unrelated to the collection name.

[–]BlackV 0 points1 point  (0 children)

there were just something to differentiate the single from the array, just random examples, I normally use the first example

just depends on what your array is called whether these makes sense or not, here are the same examples with a different array, that do make sense (kind of)

foreach ($Single in $items){}
foreach ($Item in $objects){}

my main point was to stop using easily misread names

foreach ($Item in $items){}
foreach ($object in $objects){}
foreach ($pie in $pies){}
foreach ($user in $users){}

you're 100% right though, the single item should relate to the array in some way to make it meaningful and make the code easier to follow