10

次の出力があります。

Array (
  [0] => stdClass Object (
        [id] => 20
        [news_title] => Startup finance docs in GitHub
        [news_url] => http://venturebeat.com/2013/03/06/fenwick-west-github/
        [news_root_domain] => venturebeat.com
        [news_category] =>
        [news_submitter] => 4
        [news_time] => 2013-03-06 11:20:03
        [news_points] => 0
    )
    [1] => stdClass Object (
        [id] => 21
        [news_title] => The problems with righteous investing
        [news_url] => http://gigaom.com/2013/03/07/the-problems-with-righteous-investing/
        [news_root_domain] => gigaom.com
        [news_category] =>
        [news_submitter] => 4
        [news_time] => 2013-03-08 09:14:17
        [news_points] => 0
    )
)

これらの news_url のようなものにアクセスするにはどうすればよいですか? 私はこれを試しましたが、役に立ちませんでした:

print_r $this->$record[0]->news_title;
4

2 に答える 2

2

クラス プロパティを使用しています。最初にアクセスできるかどうかを確認することをお勧めします。使用後にクラス プロパティにアクセスするとき$thisは、追加の は必要ありません。$使用するだけ$this - recordです。お気に入り

echo $this -> record[0] -> title;

record配列である有効なクラス プロパティであり、それでも機能しない場合。これも試してみてください:

echo {$this -> record[0]} -> title;
于 2013-05-07T00:16:33.377 に答える