Home › Forums › Add-ons › Repeater Field › Generate XML using sub_fields recursively › Reply To: Generate XML using sub_fields recursively
Hi @bart-gopnik
In this case, you need to create a function to loop through the returned fields and its values. Here’s an example how to do it:
// Create function that will loop through the array
function print_array_value($value){
if( is_array($value) ){
foreach( $value as $k => $the_value ){
echo '<' . $k . '>' . PHP_EOL;
print_array_value($the_value);
echo '</' . $k . '>' . PHP_EOL;
}
} else {
echo $value . PHP_EOL;
}
}
// Loop through the fields here
foreach($fields as $field){
echo '<' . $field['name'] . '>' . PHP_EOL;
// Check if this is a repeater or not
print_array_value($field['value']);
echo '</' . $field['name'] . '>' . PHP_EOL;
}
Because this is more related to PHP than ACF, kindly get in touch with PHP community for more support.
I hope this helps 🙂
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.