如何在php中访问stdClass元素?

时间:2016-01-30 13:40:35

标签: php

我查询db,我有一个数组。如何访问stdClass对象?而且我也希望serializedName属性在java serializedName中。因此,必须使用我的自定义对象类字段分配从db查询的字段。如何使用它?

 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] => 
            )

    )

2 个答案:

答案 0 :(得分:1)

试试这个:

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

答案 1 :(得分:1)

逐一尝试这个  echo $array[0]->receipt_id;