I use a multidimensional array in a foreach loop, but i dont get the right results back.
array
$mainarray = array(
array('field_name' => 'xx',
'email_label' => 'xxxx',
'validation_type' => 'xxxxx',
'validation_msg' => 'xxxxxx'),
array('field_name' => 'xx',
'email_label' => 'xxxx',
'validation_type' => 'xxxxx',
'validation_msg' => 'xxxxxx'),
// more ....
}
foreach loop
foreach($mainarray as $fieldarray){
foreach($fieldarray as $key => $value){
$body .= $value['email_label'].' - '. $value['field_name'];
}
}
i need the value’s of the key called email_label and field_name, but i dont get the right results back
Since your code that appends to
$bodyaccesses indexes of$value, your original code was effectively written to work on a three-level array.If your array is structured as you’ve posted, you don’t need the inner
foreachloop.