0

複数の配列を含む配列結果があります。第 2 レベルの配列のすべての「テキスト」フィールドを取得し、それらを 1 つの変数に結合する必要があります。私はこれを行う方法について空白を描いています

配列:

配列 (
[0] => stdClass オブジェクト (
    [created_at] => 2012 年 8 月 20 日月曜日 18:31:50 +0000
    [from_user] => CollectHW
    [from_user_id] => 769712384
    [from_user_id_str] => 769712384
    [from_user_name] => ホットウィールを集める
    [地理] =>
    [ID] => 237617956643827712
    [id_str] => 237617956643827712
    [iso_language_code] => ja
    [メタデータ] => stdClass オブジェクト (
        [result_type] => 最近 )
    [プロフィール画像のURL] => URL
    [profile_image_url_https] => URL
    [ソース] =>ウェブ**
    [テキスト] => 2 番目のツイート #step2**
    [to_user] =>
    [to_user_id] => 0
    [to_user_id_str] => 0
    [to_user_name] => )
[1] => stdClass オブジェクト (
    [created_at] => 2012 年 8 月 20 日月曜日 16:41:53 +0000
    [from_user] => CollectHW
    [from_user_id] => 769712384
    [from_user_id_str] => 769712384
    [from_user_name] => ホットウィールを集める
    [地理] =>
    [ID] => 237590287504011264
    [id_str] => 237590287504011264
    [iso_language_code] => ja
    [メタデータ] => stdClass オブジェクト (
        [result_type] => 最近 )
    [プロフィール画像のURL] => URL
    [profile_image_url_https] => URL
    [ソース] =>ウェブ**
    [テキスト] => 最初のツイート #step1**
    [to_user] =>
    [to_user_id] => 0
    [to_user_id_str] => 0
    [to_user_name] => )
)
4

2 に答える 2

1
for($i = 0; $i < count($array); $i++) {
    echo "The text for $i is: " . $array[$i][text] . "\n";
}

結果

0 のテキストは次のとおりです: 2 番目のツイート #step2**
1 のテキストは次のとおりです: 最初のツイート #step1**
于 2012-08-20T19:46:32.600 に答える
0

試す:

$text = '';

foreach($array as $item) {
    $text .= $item['text'];
}

編集:配列にはstdClassインスタンスが含まれているため、代わりに次のことを行う必要がある場合があります:

$text = '';

foreach($array as $item) {
    $text .= $item->text;
}

ほとんど同じことです。PHP オブジェクトのプロパティに配列表記を使用してアクセスできるかどうかはわかりません。最初の方法を試して、うまくいかない場合は 2 番目の方法を試してください。

于 2012-08-20T19:42:52.157 に答える