...

View Full Version : Extracting a value from a multidimensional array



nickp
11-16-2010, 10:55 AM
I'm sure this is one of those easy queries that I'm making harder! I am using an array that looks like this:


$meta_boxes[] = array(
'id' => 'person_meta_box',
'fields' => array(
array(
'name' => 'Born:',
'id' => 'date_of_birth'
),
array(
'name' => 'Died:',
'id' => 'date_of_death'
)

)
);


I am getting into a twist over how to get the field 'name' into a variable to echo to the screen. Can you help? (Sadly, simplifying the data structure is not possible!)

sybil6
11-16-2010, 11:05 AM
$meta_boxes = array(
'id' => 'person_meta_box',
'fields' => array(
array(
'name' => 'Born:',
'id' => 'date_of_birth'
),
array(
'name' => 'Died:',
'id' => 'date_of_death'
)

)
);

echo $meta_boxes["fields"][0]["name"];

poyzn
11-16-2010, 11:06 AM
for field name = Born it will be:


$var = $meta_boxes[0]['fields'][0]['name'];
echo $var;

nickp
11-16-2010, 11:24 AM
Thank you both - you've got me over a blank spell this morning!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum