CyberJunkie
CyberJunkie

Reputation: 22674

Get values from specific multidimensional array

I have multiple arrays:

$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...

How can I get for example, the value of the name element from fields array from $meta_boxes[] array with id = measurements?

Upvotes: 0

Views: 191

Answers (1)

Indranil
Indranil

Reputation: 2471

Try something like this:

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

Upvotes: 2

Related Questions