I am trying to pass a dynamic variable into a multidimensional array.
This is the actual code:
for($i = 0; $i < count($social ["#object"] -> field_sector ["und"]); $i++){
echo $social ["#object"] -> field_sector ["und"] [$i] ["taxonomy_term"] -> name;
}
Since I want to re-use this code for multiple types, I created a function
function render_multi_array ($parent, $field_name) {
for($i = 0; $i < count($parent ["#object"] -> $field_name ["und"]); $i++){
echo $parent ["#object"] -> $field_name ["und"] [$i] ["taxonomy_term"] -> name;
}
}
The issue is happening with $field_name as I am unable to provide this dynamically. Any idea how I can make this function work?
Sample array is follows:
Array
(
[#title] => Sector
[#field_name] => field_sector
[#object] => stdClass Object
(
[vid] => 1079
[uid] => 30
[vuuid] => 83ab0817-0175-4541-b20e-93611c20c026
[nid] => 1077
[type] => random_study
[field_random_id] => Array
(
[und] => Array
(
[0] => Array
(
[value] => CS_525
[format] =>
[safe_value] => CS_525
)
)
)
[field_sector] => Array
(
[und] => Array
(
[0] => Array
(
[tid] => 411
[taxonomy_term] => stdClass Object
(
[tid] => 411
[vid] => 10
[name] => Sample title goes here.
)
)
[1] => Array
(
[tid] => 248
[taxonomy_term] => stdClass Object
(
[tid] => 248
[vid] => 10
[name] => Energy
)
)
)
)