数组数据操作和检索

时间:2013-05-10 18:35:03

标签: php arrays

所以我有一个多维数组:

我用$array= call_user_func_array('array_merge', $array);

将其展平了一个级别

现在,当我尝试使用

访问约会时
foreach($array as $field)
{
   echo $field['Section_title'];      // echo id 

}

我通过所有嵌套数组获得结果,但我只想引用每个单独的数组。而不是获得#1,我想获得#2。有人可以教我如何正确读取和引用嵌套数组吗?

  

1. {条件和症状,紧急联系人等}

     

2. {条件和症状}

数组

Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [Section_title] => Conditions and Symptoms
                    [section_subtitle] => Does the patient have 
                    [additional_info] => 
                    [section_disclaimer] => 
                    [disclaimer_title] => 
                    [section_makercol] => 
                    [field_title_1] => Tuberculosis
                    [field_title_2] => Chronic cough
                    [field_title_3] => Asthma
                    [field_title_4] => Diabetes

                )

            [1] => Array
                (
                    [Section_title] => Emergency Contacts
                    [section_subtitle] => 
                    [additional_info] => 
                    [section_disclaimer] => 
                    [disclaimer_title] => 
                    [section_makercol] => 
                    [field_title_1] => Name
                    [field_title_2] => Phone #
                    [field_title_3] => Address
                    [field_title_4] => City

                )

            [2] => Array
               ( 

               )
)

1 个答案:

答案 0 :(得分:2)

您可以遍历键值:

foreach($array as $field)
{
   foreach ($field as $key => $value){
       echo $field[$key]; //
   }
}