I have something like this:
function print_element($array, $field){
return "Element: {$array[$field]}";
}
$array['name_en'] = 'English name';
echo print_element($array, 'name_en');
I wish to access a property within an array that belongs to the main array like this:
$array['english_values']['name_en'] = 'English name';
echo print_element($array, "['english_values']['name_en']");
Is there a way to accomplish this?
Thx in advance.
echo print_element($array['english_values'], 'name_en');
Pass just the string 'english_values,name_en' to your function. Inside the function, explode the string on the comma, then loop through the array and assign $array = $array[$thisKey]
on each pass. You may also wish to check that it is_array($array)
on each pass.
You have the array and also the keys try this:
function print_var($val) {
echo "VAR: {$val} <br/>";
}
$array['english_values']['name_en'] = 'English name';
print_var($array['english_values']['name_en']);
// OUTPUT
// VAR: English name
echo
before it. Your function handles theecho
internally - Sampson 2012-04-03 22:03