in reply to cool way of manipulating array elements

Do be clever. Write your code so that it is understandable. Use a foreach loop.

  • Comment on Re: cool way of manipulating array elements

Replies are listed 'Best First'.
Re^2: cool way of manipulating array elements
by pemungkah (Priest) on Sep 02, 2011 at 20:27 UTC
    I wish I could upvote this multiple times. map is very cool, and can give you a marvelously compact syntax, but a simple foreach or while loop does the same thing and is (usually) easier to read.

      I use map, not for its "compact syntax", but depending on the use case. This example, in my opinion, is the perfect use case for map: transform an array using some criteria and return a new array.

      for (or, foreach if you like) has its place, but I don't find it inherently more readable than map.