从特定的多维数组中获取值

时间:2011-12-13 21:42:27

标签: php arrays loops multidimensional-array

我有多个阵列:

$meta_boxes[] = array(
    'id' => 'measurements',
    'title' => 'Measurements',
    'fields' => array(  
        array(
            'name' => 'Length',
            'id' => 'length',
            'type' => 'text',
            'std' => ''
        ),
        array(
            'name' => 'Manufacturer Length',
            'id' => 'manufacturer_length',
            'type' => 'text',
            'std' => ''
        )                   
    )
);

$meta_boxes[] = array(
        'id' => 'colors',
        'title' => 'Colors',
        'fields' => array(  
            array(
                'name' => 'exterior',
                'id' => 'exterior',
                'type' => 'text',
                'std' => ''
            etc...

我如何从name数组fields数组$meta_boxes[]数组得到id = measurements元素的值?

1 个答案:

答案 0 :(得分:2)

尝试这样的事情:

foreach ($meta_boxes as $meta_box) {
    if($meta_box['id'] !== 'measurements') {
        continue;
    }
    $output = $meta_box['fields'];
    break;
}