PHP nested ‘foreach’ loop only using last value of array

I wrote the following loop to create WordPress custom controls quicker:

<?php
  /* Creates "Color Scheme" section */
  $wp_customize->add_panel('color_scheme', array(
    'title' => 'Color Scheme',
    'priority' => 120,
  ));
    /* Creates "Navbar" section */
    $wp_customize->add_section('navbar', array(
      'title'    => 'Navbar',
      'description' => '',
      'priority' => 120,
      'panel' => 'color_scheme'
    ));
      /* Navbar Color Controls */
      $color_controls = array("menu-bg-color", "menu-button-color", "menu-site-title-color", "menu-overlay-bg-color", "menu-items-color");
      $color_labels = array("Background Color", "Button Color", "Title Color", "Overlay Background Color", "Overlay Item Color");
      foreach($color_controls as $control) {
        foreach($color_labels as $label) {
          $wp_customize->add_setting($control);
          $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, $control, array(
            'label' => $label,
            'section' => 'navbar',
            'settings' => $control
          )));
        }
      }
?>

This is the outcome: Screenshot of my WordPress customizer
Its not looping through the labels and its only using the last value.

Read more here: PHP nested ‘foreach’ loop only using last value of array

Leave a Reply

Your email address will not be published. Required fields are marked *