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

但是现在我不想循环遍历它,而只是取回数组 model1 的名称。
我该怎么做呢?我不需要数组模型 1 的值,只需要名称

4

4 回答 4

0

如果要从关联数组中获取键,请使用以下结构:

foreach( $array as $key => $value )
{
     echo($key);
}
于 2013-04-15T07:37:24.073 回答
0
 $array = 'your returned array'

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

更一般地说,如果你有关联数组,那么你可以使用foreach循环

foreach($array as $key=>$value)
{
   print_r($value);
}
于 2013-04-15T07:38:27.653 回答
0
print_r($x['cytec']['model1']['title']);
于 2013-04-15T07:41:23.013 回答
0

要获取关联数组的键,您还可以使用:

while ($cytec_name = current($cytec)) {
   echo key($cytec).'<br />';
}
于 2013-04-15T07:41:44.533 回答