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

PHP 配列への追加と上書き

Last updated at Posted at 2021-01-27

簡単にまとめ書き
環境:PHP Version 7.4.13

まず2次元配列を作ります。


$alphabet = array( "a", array( "b-a", "b-b", "b-c", "b-d"), "c", "d", "e");

var_dump($alphabet);

var_dump()関数 に放り込んで配列の構造を表示させます。
( ↓ ブラウザの画面)


array (size=5)
  0 => string 'a' (length=1)
  1 => 
    array (size=4)
      0 => string 'b-a' (length=3)
      1 => string 'b-b' (length=3)
      2 => string 'b-c' (length=3)
      3 => string 'b-d' (length=3)
  2 => string 'c' (length=1)
  3 => string 'd' (length=1)
  4 => string 'e' (length=1)

echoでの表示

echo $alphabet[4]; → e
echo $alphabet[1][2]; → b-c

echo $alphabet; → エラー
echo $alphabet[1]; → エラー

配列はechoでは表示されない。

配列への追加と上書き

イメージしやすいように画像にしました。

PHP配列への追加と上書き_補完版.png

配列の結合や追加のために用意されている関数

  • array_merge()
  • array_merge_recursive()
  • array_push()

など、結合や追加のために用意されている関数があります。

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?