2
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 5 years have passed since last update.

php5.4以降の配列の書き方

Last updated at Posted at 2018-02-05

とても今更感が満載なのですが、php5.4から下記のような書き方が可能となりました。

array_5_4.php
$arr = [
    1 => "横浜市",
    2 => "大阪市",
    3 => "名古屋市",
    4 => "札幌市",
    5 => "福岡市",
    6 => "神戸市",
];

リファレンスにも書いてる。

1 何故今更こんなことを?

何故こんなことを今更紹介するのかと言いますと、これまで何年もPHPをやっておきながら自分はこの書き方を知らなかったからなのです......
どこかで無意識に一度くらい書いたことはあるかもしれませんが、とある場で指摘をいただくまでとにかく自分は知りませんでした。(言い訳をすると、初め使っていたのがPHP5.3だったから仕方がなかっ(ry )

2 ちなみに、php5.3以前では

ちなみになのですが、php5.3以前では下記のような書き方をします。

array_5_3.php
$arr = array(
    1 => "横浜市",
    2 => "大阪市",
    3 => "名古屋市",
    4 => "札幌市",
    5 => "福岡市",
    6 => "神戸市",
);

3 終わりに

いらっしゃらないような気がしますが、もしこの記事を見てハッとされた方は是非ご自身の配列の書き方を見直して見てください__(:3」∠)__

2018/2/7追記
申し訳ございません。冒頭の本文の一部に文法的な誤りがありましたので、修正しました。

2
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
2
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?