I am trying to return the array from checkboxes in a field so that I can use both the key as a variable, and the label as a variable, both in a foreach loop. Here’s the code:
<?php
// icons
foreach (get_sub_field('nav_widget_platforms') as $key => $value) {
echo '<div class="mps-nav-context"><i class="icon-'.$value.'" title="'.$key.'"></i><span>'.$key.'</span></div>';
}
?>
So if the checkbox “cloud : eCommerce” is selected, the $value should be “cloud” and the $key should be “eCommerce.” Unfortunately $key is returning numbers, not the labels for the checkboxes, though $value is correct.
What am I doing wrong?