显示数组中的某些值

时间:2013-11-11 07:33:51

标签: php arrays

我有一个像这样的数组..

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'值?

3 个答案:

答案 0 :(得分:1)

foreach ($arr as $class){
   echo "Id:{$class->id} subject:{$class->subject}";
}

答案 1 :(得分:0)

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

foreach($arr as $obj){
    echo $obj->id;
    echo $obj-subject;
}

答案 2 :(得分:0)

你必须对你的数组和每个项目进行迭代,显示id和subject字段。

伪代码

foreach($myArray as $item) {
    echo $item->id.' - '.$item->subject;
}