Home › Forums › Add-ons › Repeater Field › Generate XML using sub_fields recursively › Reply To: Generate XML using sub_fields recursively
Hi @bart-gopnik
The easiest way would be checking if the current key is a number or not like this:
// Create function that will loop through the array
function print_array_value($value){
if( is_array($value) ){
foreach( $value as $k => $the_value ){
if( is_numeric($k) ){echo '<' . $k . '>' . PHP_EOL;}
print_array_value($the_value);
if( is_numeric($k) ){echo '</' . $k . '>' . PHP_EOL;}
}
} else {
echo $value . PHP_EOL;
}
}
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;
}
I hope this makes sense 🙂
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.