1

我有一个这样的数组..

array (size=15)
0 => 
object(stdClass)[1]
  public 'id' => string '252bb4ffbc' (length=10)
  public 'title' => string '' (length=0)
  public 'subject' => string 'Monthly Volunteer Newsletter' (length=28)
  public 'send_time' => string '2011-10-18 21:15:45' (length=19)
  public 'type' => string 'regular' (length=7)
1 => 
object(stdClass)[2]
  public 'id' => string '3e9e5cb3c2' (length=10)
  public 'title' => string 'November 2011' (length=13)
  public 'subject' => string 'Children's Bureau Volunteer Newsletter' (length=38)
  public 'send_time' => string '2011-11-08 19:49:55' (length=19)
  public 'type' => string 'regular' (length=7)
2 => 
object(stdClass)[3]
  public 'id' => string '0608fee9c1' (length=10)
  public 'title' => string '' (length=0)
  public 'subject' => string 'Children's Bureau Monthly Volunteer Newsletter December  2011' (length=60)
  public 'send_time' => string '2011-12-28 17:32:29' (length=19)
  public 'type' => string 'regular' (length=7)

现在我如何使用 php 只显示 'id' 和 'subject' 值?

4

3 回答 3

1
foreach ($arr as $class){
   echo "Id:{$class->id} subject:{$class->subject}";
}
于 2013-11-11T07:36:14.357 回答
0

$arr 是包含所有元素的数组

foreach($arr as $obj){
    echo $obj->id;
    echo $obj-subject;
}
于 2013-11-11T07:36:01.613 回答
0

您必须对数组进行迭代,并为每个项目显示 id 和主题字段。

伪代码

foreach($myArray as $item) {
    echo $item->id.' - '.$item->subject;
}
于 2013-11-11T07:38:14.180 回答