4

I made my first closure in PHP, but I'm not happy.

For me Javascript closure are nicer.

What do you think about?

Comments
  • 4
    One liner if might look a tad cleaner. return key_exists($v, $aTrasformaCampi) ? $aTrasformaCampi[$v] : $v;
  • 0
    Agree, JS, C#, and Swift look nicer than this, but this isn't bad
  • 1
    Yeah, anonymous functions suck in PHP. But with modern PHP (7.1+ I guess) you can simply do it like this:

    return $aTrasformaCampi[$v] : $v;

    And PHP 7.4 will introduce arrow function syntax, so the entire thing will look like this:

    $daa = array_map(fn ($v) => $aTrasformaCampi[$v] : $v);
  • 0
    also, 2 maps, while the trim could be done inside the anon? :v
  • 0
    JK, it's not that bad.
  • 1
    _I only see italics_
  • 0
    Your indentation is weirdly inconsistent
  • 0
    But ++ for Monokai 2 👍
Add Comment