1
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 for文を用いて配列に配列を確認する

Posted at

目的

  • for文を用いて全く同じ配列データをさらに配列に格納する方法を下記に記載する

実施環境

  • ハードウェア環境
項目 情報
OS macOS Catalina(10.15.5)
ハードウェア MacBook Pro (13-inch, 2020, Four Thunderbolt 3 ports)
プロセッサ 2 GHz クアッドコアIntel Core i5
メモリ 32 GB 3733 MHz LPDDR4
グラフィックス Intel Iris Plus Graphics 1536 MB

コードの例

  • ["test01", "test02", "test03"]という配列さらに配列$main_arrayに10回格納するコードを下記に記載する。

    $i = 0;
    
    for ($i = 1; $i <= 10; $i++){                
        $main_array[] = [
            "test01",
            "test02",
            "test03",
        ];
    }
    
    var_dump($main_array);
    
  • 上記コードの実行結果を下記に記載する。

    array(10) {
      [0]=>
      array(3) {
        [0]=>
        string(6) "test01"
        [1]=>
        string(6) "test02"
        [2]=>
        string(6) "test03"
      }
      [1]=>
      array(3) {
        [0]=>
        string(6) "test01"
        [1]=>
        string(6) "test02"
        [2]=>
        string(6) "test03"
      }
      [2]=>
      array(3) {
        [0]=>
        string(6) "test01"
        [1]=>
        string(6) "test02"
        [2]=>
        string(6) "test03"
      }
      [3]=>
      array(3) {
        [0]=>
        string(6) "test01"
        [1]=>
        string(6) "test02"
        [2]=>
        string(6) "test03"
      }
      [4]=>
      array(3) {
        [0]=>
        string(6) "test01"
        [1]=>
        string(6) "test02"
        [2]=>
        string(6) "test03"
      }
      [5]=>
      array(3) {
        [0]=>
        string(6) "test01"
        [1]=>
        string(6) "test02"
        [2]=>
        string(6) "test03"
      }
      [6]=>
      array(3) {
        [0]=>
        string(6) "test01"
        [1]=>
        string(6) "test02"
        [2]=>
        string(6) "test03"
      }
      [7]=>
      array(3) {
        [0]=>
        string(6) "test01"
        [1]=>
        string(6) "test02"
        [2]=>
        string(6) "test03"
      }
      [8]=>
      array(3) {
        [0]=>
        string(6) "test01"
        [1]=>
        string(6) "test02"
        [2]=>
        string(6) "test03"
      }
      [9]=>
      array(3) {
        [0]=>
        string(6) "test01"
        [1]=>
        string(6) "test02"
        [2]=>
        string(6) "test03"
      }
    }
    
1
0
2

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