foreach多次元配列

投稿者: | 2021年9月10日

phpでmysqlから多次元配列を表示する

Array
(
    [0] => ADOFetchObj Object
        (
            [CATE_ID] => 250
            [CATE_FLG1] => 1
            [CATE_C_ID] => 6
            [CATE_REMARKS1] => 1R
            [CATE_REMARKS2] => 
            [CATE_REMARKS3] => 
            [CATE_UPDATE1] => 2021-09-21
            [CATE_UPDATE2] => 2021-09-21
        )

    [1] => ADOFetchObj Object
        (
            [CATE_ID] => 249
            [CATE_FLG1] => 1
            [CATE_C_ID] => 6
            [CATE_REMARKS1] => 1K
            [CATE_REMARKS2] => 
            [CATE_REMARKS3] => 
            [CATE_UPDATE1] => 2021-09-21
            [CATE_UPDATE2] => 2021-09-21
        )

    [2] => ADOFetchObj Object
        (
            [CATE_ID] => 248
            [CATE_FLG1] => 1
            [CATE_C_ID] => 6
            [CATE_REMARKS1] => 1DK
            [CATE_REMARKS2] => 
            [CATE_REMARKS3] => 
            [CATE_UPDATE1] => 2021-09-21
            [CATE_UPDATE2] => 2021-09-21
        )

    [3] => ADOFetchObj Object
        (
            [CATE_ID] => 247
            [CATE_FLG1] => 1
            [CATE_C_ID] => 6
            [CATE_REMARKS1] => 1LDK
            [CATE_REMARKS2] => 
            [CATE_REMARKS3] => 
            [CATE_UPDATE1] => 2021-09-21
            [CATE_UPDATE2] => 2021-09-21
        )

    [4] => ADOFetchObj Object
        (
            [CATE_ID] => 246
            [CATE_FLG1] => 1
            [CATE_C_ID] => 6
            [CATE_REMARKS1] => 1SLDK
            [CATE_REMARKS2] => 
            [CATE_REMARKS3] => 
            [CATE_UPDATE1] => 2021-09-21
            [CATE_UPDATE2] => 2021-09-21
        )

    [5] => ADOFetchObj Object
        (
            [CATE_ID] => 245
            [CATE_FLG1] => 1
            [CATE_C_ID] => 6
            [CATE_REMARKS1] => 2K
            [CATE_REMARKS2] => 
            [CATE_REMARKS3] => 
            [CATE_UPDATE1] => 2021-09-21
            [CATE_UPDATE2] => 2021-09-21
        )

    [6] => ADOFetchObj Object
        (
            [CATE_ID] => 244
            [CATE_FLG1] => 1
            [CATE_C_ID] => 6
            [CATE_REMARKS1] => 2DK
            [CATE_REMARKS2] => 
            [CATE_REMARKS3] => 
            [CATE_UPDATE1] => 2021-09-21
            [CATE_UPDATE2] => 2021-09-21
        )

    [7] => ADOFetchObj Object
        (
            [CATE_ID] => 243
            [CATE_FLG1] => 1
            [CATE_C_ID] => 6
            [CATE_REMARKS1] => 2LDK
            [CATE_REMARKS2] => 
            [CATE_REMARKS3] => 
            [CATE_UPDATE1] => 2021-09-21
            [CATE_UPDATE2] => 2021-09-21
        )

    [8] => ADOFetchObj Object
        (
            [CATE_ID] => 242
            [CATE_FLG1] => 1
            [CATE_C_ID] => 6
            [CATE_REMARKS1] => 2SLDK
            [CATE_REMARKS2] => 
            [CATE_REMARKS3] => 
            [CATE_UPDATE1] => 2021-09-21
            [CATE_UPDATE2] => 2021-09-21
        )

    [9] => ADOFetchObj Object
        (
            [CATE_ID] => 241
            [CATE_FLG1] => 1
            [CATE_C_ID] => 6
            [CATE_REMARKS1] => 3K
            [CATE_REMARKS2] => 
            [CATE_REMARKS3] => 
            [CATE_UPDATE1] => 2021-09-21
            [CATE_UPDATE2] => 2021-09-21
        )

    [10] => ADOFetchObj Object
        (
            [CATE_ID] => 240
            [CATE_FLG1] => 1
            [CATE_C_ID] => 6
            [CATE_REMARKS1] => 3DK
            [CATE_REMARKS2] => 
            [CATE_REMARKS3] => 
            [CATE_UPDATE1] => 2021-09-21
            [CATE_UPDATE2] => 2021-09-21
        )

    [11] => ADOFetchObj Object
        (
            [CATE_ID] => 239
            [CATE_FLG1] => 1
            [CATE_C_ID] => 6
            [CATE_REMARKS1] => 3LDK
            [CATE_REMARKS2] => 
            [CATE_REMARKS3] => 
            [CATE_UPDATE1] => 2021-09-21
            [CATE_UPDATE2] => 2021-09-21
        )

    [12] => ADOFetchObj Object
        (
            [CATE_ID] => 238
            [CATE_FLG1] => 1
            [CATE_C_ID] => 6
            [CATE_REMARKS1] => 3SLDK
            [CATE_REMARKS2] => 
            [CATE_REMARKS3] => 
            [CATE_UPDATE1] => 2021-09-21
            [CATE_UPDATE2] => 2021-09-21
        )

    [13] => ADOFetchObj Object
        (
            [CATE_ID] => 237
            [CATE_FLG1] => 1
            [CATE_C_ID] => 6
            [CATE_REMARKS1] => 4K
            [CATE_REMARKS2] => 
            [CATE_REMARKS3] => 
            [CATE_UPDATE1] => 2021-09-21
            [CATE_UPDATE2] => 2021-09-21
        )

    [14] => ADOFetchObj Object
        (
            [CATE_ID] => 236
            [CATE_FLG1] => 1
            [CATE_C_ID] => 6
            [CATE_REMARKS1] => 4DK
            [CATE_REMARKS2] => 
            [CATE_REMARKS3] => 
            [CATE_UPDATE1] => 2021-09-21
            [CATE_UPDATE2] => 2021-09-21
        )

)

その1

<?php
foreach ($items as $key1 => $value1) {
    print "$value1->CHAT1_CO_NAME"."<br>"."$value1->CHAT1_MESSAGE"."<br>"; //「.」は文字列連結
}

その2

  <?php

  $html="";
    foreach ($items as $item) {
        $html .='<p class="kaiwa-text">'.$item->USER_ID.'<br />'.$item->USER_MESSAGE.'</p>';
    }

echo"$html";

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

CAPTCHA