0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

PHP:関数:アロー関数は奇妙すぎるがコード短縮になるので積極的に使う

Last updated at Posted at 2023-02-24

アロー関数や無名関数は本当に奇妙すぎる。こういうタイプはそういう仕様だと覚えるのみ。
コード短縮になるので積極的に使い倒す。

無名関数もだが、アロー関数が奇妙なのは、

  1. 配列の各要素の変数名が、使用時に初登場させればそれで使えてしまう(foreachのように定義をしていないというのに)。
  2. 無名関数は function と書くのに、なぜか fn と省略している

便利だから使い倒すが奇妙さは続く。。

function funcname(string ...$cards): array {
    return array_map(fn ($card) => substr($card, 1), $cards);
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?