How not to repeat array in a function to use foreach

This works fine, but it’s goofy to me as I don’t know even what to search for (or if the question is titled correctly) to learn how to accomplish not repeating the $slide_panels array within the christina_slide_in_panels() function below it and outside it.

Sadly, this question was closed but the answer by Steve is in the comments. The question was not answered by reading the “duplicate” post accepted answer, at least not specifically.

//* register slide panels

$slide_panels = array (
            'slide-1'       => 'Slide Panel One',
            'slide-2'       => 'Slide Panel Two',
            'slide-3'       => 'Slide Panel Three',
            'slide-4'       => 'Slide Panel Four',
            );


foreach ( $slide_panels as $id => $slide_panel) {
    register_sidebar(
        array (
                'name'          => __( $slide_panel, 'christina' ),
                'id'            => $id,
                'before_widget' => '<aside id="%1$s" class="slide-widget %2$s">',
                'after_widget'  => '</aside>',
                'before_title'  => '<h3 class="slide-widget-title">',
                'after_title'   => '</h3>',
        ));

}


//* create the panels

function christina_slide_in_panels() {

   //======== > HOW TO NOT REPEAT THIS < ========
   $slide_panels = array (
            'slide-1'       => 'Slide Panel One',
            'slide-2'       => 'Slide Panel Two',
            'slide-3'       => 'Slide Panel Three',
            'slide-4'       => 'Slide Panel Four',
            );  

    echo '<!-- begin slide panels --><div class="slide-in-panels-parent">';

    foreach ( $slide_panels as $id => $slide_panel) {

        if ( is_active_sidebar( $id ) ) {

            echo '<div class="slide-panel" id="'.$id.'" aria-expanded="false" aria-hidden="true">';
            // id used on the toggle to get this slide in

            dynamic_sidebar( $id );

            echo '</div><!-- close '.$id.' -->';
        }
        //end endif;
    }
    //end foreach

    echo '</div><!-- end slide panels -->';
    //close parent;


}
add_action('genesis_after', 'christina_slide_in_panels');

Related posts