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

PHP 連想配列まとめ

Last updated at Posted at 2020-01-05

目的

  • PHPの連想配列の書き方をまとめる

書き方の例

  • 連想配列は若干難しそうに感じるが、通常の配列の値の順番を示す[0]などがキーになっただけである。
  • 下記に連想配列の書き方の例を記載する。
$変数A = array(
  "キーA" => "入れる値A",
  "キーB" => "入れる値B",
  "キーC" => "入れる値C"
);

//キーAに格納された値Aを出力
echo $変数A["キーA"];

//キーBに格納された値Bを出力
echo $変数A["キーB"];

//キーCに格納された内容を更新
$変数A["キーC"] = "入れる値D";

PHP 5.4以降の例

  • 前述した処理をPHP5.4以降のバージョンでのみ記載できる短縮系で記載する。
$変数A = [
  "キーA" => "入れる値A",
  "キーB" => "入れる値B",
  "キーC" => "入れる値C"
];
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?