2011-07-15 106 views
1

我的調試($ planDetails)輸出如下。爲什麼我不能訪問數組元素以標準的方式,如:訪問特定的數組()元素

foreach ($planDetails as $planRow) : 
     echo $planRow['Plan']['Applicant']['name']; 
    endforeach; 

我得到未定義指數:計劃錯誤?

我也試過了: echo $ planRow ['Plan'] [] ['name'];

Array 
(
[PlanDetail] => Array 
     (
      [id] => 54 
      [name] => BasicOne 
     ) 


[Plan] => Array 
     (
      [0] => Array 
       (
        [id] => 255 
        [monthly_cost] => 20.23 
        [age_id] => 14 
        [applicant_id] => 8 
        [plan_detail_id] => 54 
        [Age] => Array 
         (
          [id] => 14 
          [name] => 18-64 
         ) 

        [Applicant] => Array 
         (
          [id] => 8 
          [name] => Subscriber +2 
         ) 
       ) 
    [2] => Array 
       (
        [id] => 254 
        [monthly_cost] => 15.50 
        [age_id] => 14 
         [applicant_id] => 27 
       [plan_detail_id] => 54 
        [Age] => Array 
         (
          [id] => 14 
          [name] => 18-64 
         ) 

        [Applicant] => Array 
         (
          [id] => 27 
          [name] => Subscriber + 1 
         ) 

       ) 
) 

回答

3
foreach ($planDetails['Plan'] as $plan) { 
    echo $plan['Applicant']['name']; 
} 
+0

呃!謝謝。在時間限制結束後(約8分鐘),我會接受你的回答。 – OldWest

2

你錯過了在陣列中的水平。你想要

$planRow['Plan'][0]['Applicant']['name'];