2013-04-15 44 views
0

我有一個多維數組多維數組循環

return array(

// This level separates instances by their instance key. 
'cytec' => array(

    // This level separates models by their model key. 
    'model1' => array(

     'title' => 'Business card model 1 title', 
     'preview' => 'public path to preview image', 
     'pdf'  => 'web safe path to PDF to generate from', 
     'fields' => array(

      'title' => array(
       'label'  => 'Title', 
       'type'   => 'text', 
       'required'  => true, 
       'coordinate-x' => 30, 
       'coordinate-y' => 20, 
       'rules'  => 'required', 
      ), 

      'phone' => array(
       'label'  => 'Phone', 
       'type'   => 'text', 
       'help'   => 'syntax +32(0)3 485 85 53', 
       'coordinate-x' => 40, 
       'coordinate-y' => 20, 
       'rules'  => '', 
      ), 

      'position' => array(
       'label'  => 'Position', 
       'type'   => 'select', 
       'options'  => array(
        'developer' => 'Web Developer', 
        'designer' => 'Web Designer', 
       ), 
       'required'  => true, 
       'coordinate-x' => 40, 
       'coordinate-y' => 20, 
       'rules'  => 'required|in:developer,designer', 
      ), 
     ), 
    ), 
), 
); 

,我得到這個返回

Array ( 
    [model1] => Array ( 
        [title] => Business card model 1 title 
        [preview] => public path to preview image 
        [pdf] => web safe path to PDF to generate from 
        [fields] => Array ( 
           [title] => Array ( 
               [label] => Title 
               [type] => text 
               [required] => 1 
               [coordinate-x] => 30 
               [coordinate-y] => 20 
               [rules] => required 
              ) 
           [phone] => Array ( 
               [label] => Phone 
               [type] => text 
               [help] => syntax +32(0)3 485 85 53 
               [coordinate-x] => 40 
               [coordinate-y] => 20 
               [rules] => 
              ) 
           [position] => Array ( 
               [label] => Position 
               [type] => select 
               [options] => Array ( 
                   [developer] => Web Developer 
                   [designer] => Web Designer 
                  ) 
               [required] => 1 
               [coordinate-x] => 40 
               [coordinate-y] => 20 
               [rules] => required|in:developer,designer 
              ) 
          ) 
       ) 
) 

但現在我通過這個wan't循環和剛剛獲得數組名MODEL1回來。
我該怎麼做?我不需要陣列模式1只是名字的值

+0

你的意思是標題..? – alwaysLearn

+0

是標題模型1 – user1994529

+0

水平1處的'cytec'是否已修復......或者它可以更改..? – alwaysLearn

回答

0

如果你想拿到鑰匙了一個關聯數組,使用以下結構:

foreach($array as $key => $value) 
{ 
    echo($key); 
} 
0
$array = 'your returned array' 

echo $requiredValue = $array['cytec']['model1']['title']; 

更一般地,如果你有關聯數組,那麼你可以使用foreach循環

foreach($array as $key=>$value) 
{ 
    print_r($value); 
} 
0
print_r($x['cytec']['model1']['title']); 
0

爲了得到一個關聯數組的鍵,你也可以用:

while ($cytec_name = current($cytec)) { 
    echo key($cytec).'<br />'; 
}