2016-01-30 52 views
1

我查詢數據庫,我有一個數組。我怎樣才能訪問stdClass對象?我還想要像serializedName中的serializedName屬性。所以,從db中查詢的字段必須用我的自定義對象類字段進行賦值。如何使用它?如何在php中訪問stdClass元素?

Array 
    (
     [0] => stdClass Object 
      (
       [receipt_id] => 1 
       [defect] => asd 
       [tec_report] => sad 
       [doc_number] => asd 
       [warrant] => 12 
       [warrant_start] => 2016-01-05 
       [warrant_end] => 2016-01-29 
       [repair_time] => 3 
       [receipt_date] => 2016-01-05 
       [delivery_date] => 
       [service_type_id] => 0 
       [service_price] => 0 
       [part_price] => 0 
       [pay_type] => 
       [labour] => 0 
       [summary] => 0 
       [technician_id] => 
       [customer_id] => 0 
       [device_id] => 0 
       [seri_number] => 
      ) 

     [1] => stdClass Object 
      (
       [receipt_id] => 2 
       [defect] => asdsad 
       [tec_report] => asds 
       [doc_number] => 
       [warrant] => 
       [warrant_start] => 
       [warrant_end] => 
       [repair_time] => 
       [receipt_date] => 2016-01-05 
       [delivery_date] => 
       [service_type_id] => 1 
       [service_price] => 12 
       [part_price] => 12 
       [pay_type] => 
       [labour] => 12 
       [summary] => 12 
       [technician_id] => 
       [customer_id] => 21 
       [device_id] => 12 
       [seri_number] => 
      ) 

    ) 

回答

1

一個
echo $array[0]->receipt_id嘗試一下本作之一;

+0

謝謝你們。我忘了PHP是有彈性的:)。 – hkaraoglu

1

試試這個:

foreach($yourArray as $val){ 
echo $val->receipt_id; 
echo "<br/>".$val->defect; 
}