如何从PHP中的Query中获取此数组结果中的实例?

时间:2011-08-02 16:12:35

标签: php arrays

我在一个名为$result

的变量中有一个查询结果数组

以下是此变量的var_dump()

http://pastebin.com/pc53Pmgf

array(3) {
  [0]=>
  object(stdClass)#23 (25) {
    ["procedure_id"]=>
    string(1) "1"
    ["patient_id"]=>
    string(1) "1"
    ["name_id"]=>
    string(1) "1"
    ["department_id"]=>
    string(1) "1"
    ["dosage_id"]=>
    NULL
    ["edocument"]=>
    string(10) "Bruce1.jpg"
    ["user_id"]=>
    string(1) "0"
    ["duration"]=>
    string(8) "02:26:00"
    ["submitted"]=>
    string(19) "2011-07-31 19:56:29"
    ["comment"]=>
    string(0) ""
    ["patient_age"]=>
    string(2) "34"
    ["patient_height"]=>
    string(4) "1.34"
    ["patient_weight"]=>
    string(2) "45"
    ["patient_gender"]=>
    string(4) "Male"
    ["name"]=>
    string(10) "Cardiology"
    ["procedure_name_id"]=>
    string(1) "1"
    ["procedure_name"]=>
    string(5) "IVH 2"
    ["procedure_description"]=>
    string(0) ""
    ["dosage_emitted"]=>
    NULL
    ["dosage_absorbed"]=>
    NULL
    ["dosage_period"]=>
    NULL
    ["event_id"]=>
    string(1) "1"
    ["time"]=>
    string(8) "12:34:00"
    ["success"]=>
    string(3) "Yes"
    ["event"]=>
    string(5) "start"
  }
  [1]=>
  object(stdClass)#24 (25) {
    ["procedure_id"]=>
    string(1) "1"
    ["patient_id"]=>
    string(1) "1"
    ["name_id"]=>
    string(1) "1"
    ["department_id"]=>
    string(1) "1"
    ["dosage_id"]=>
    NULL
    ["edocument"]=>
    string(10) "Bruce1.jpg"
    ["user_id"]=>
    string(1) "0"
    ["duration"]=>
    string(8) "02:26:00"
    ["submitted"]=>
    string(19) "2011-07-31 19:56:29"
    ["comment"]=>
    string(0) ""
    ["patient_age"]=>
    string(2) "34"
    ["patient_height"]=>
    string(4) "1.34"
    ["patient_weight"]=>
    string(2) "45"
    ["patient_gender"]=>
    string(4) "Male"
    ["name"]=>
    string(10) "Cardiology"
    ["procedure_name_id"]=>
    string(1) "1"
    ["procedure_name"]=>
    string(5) "IVH 2"
    ["procedure_description"]=>
    string(0) ""
    ["dosage_emitted"]=>
    NULL
    ["dosage_absorbed"]=>
    NULL
    ["dosage_period"]=>
    NULL
    ["event_id"]=>
    string(1) "2"
    ["time"]=>
    string(8) "14:50:00"
    ["success"]=>
    string(3) "Yes"
    ["event"]=>
    string(3) "sds"
  }
  [2]=>
  object(stdClass)#25 (25) {
    ["procedure_id"]=>
    string(1) "1"
    ["patient_id"]=>
    string(1) "1"
    ["name_id"]=>
    string(1) "1"
    ["department_id"]=>
    string(1) "1"
    ["dosage_id"]=>
    NULL
    ["edocument"]=>
    string(10) "Bruce1.jpg"
    ["user_id"]=>
    string(1) "0"
    ["duration"]=>
    string(8) "02:26:00"
    ["submitted"]=>
    string(19) "2011-07-31 19:56:29"
    ["comment"]=>
    string(0) ""
    ["patient_age"]=>
    string(2) "34"
    ["patient_height"]=>
    string(4) "1.34"
    ["patient_weight"]=>
    string(2) "45"
    ["patient_gender"]=>
    string(4) "Male"
    ["name"]=>
    string(10) "Cardiology"
    ["procedure_name_id"]=>
    string(1) "1"
    ["procedure_name"]=>
    string(5) "IVH 2"
    ["procedure_description"]=>
    string(0) ""
    ["dosage_emitted"]=>
    NULL
    ["dosage_absorbed"]=>
    NULL
    ["dosage_period"]=>
    NULL
    ["event_id"]=>
    string(1) "3"
    ["time"]=>
    string(8) "15:00:00"
    ["success"]=>
    string(3) "Yes"
    ["event"]=>
    string(3) "end"
  }
}

我想访问实例[“dosage_id”]。如何将代码编写到此>

我尝试了所有这些:

$result["dosage_id"];
$result[0]["dosage_id"];
$result->"dosage_id";

由于

3 个答案:

答案 0 :(得分:2)

数组结果是对象,如

array(3) {
  [0]=>
  object(stdClass)#23 (25) {

的信息。由于此类具有公共属性,$result[0]->dosage_id将检索第一个对象的dosage_id属性值。

答案 1 :(得分:2)

喜欢这个

$result[0]->dosage_id

$result[0]是一个对象,以及您使用->

访问的属性

答案 2 :(得分:0)

试试这个:$result[0]->dosage_id;