Get specific sidebars $wp_registered_sidebars [closed]

This is a generic PHP question. You need to check whether the $sidebar_id key is set in $dynamic_widget_areas as you loop through. This proof of concept code should give you the idea.

$dynamic_widget_areas = array(
  'sidebar-1' => 'stuff',
);
global $wp_registered_sidebars;
$output="";
foreach($wp_registered_sidebars as $sidebar_id => $sidebar) {
  $output .= "<option";
  if(isset($dynamic_widget_areas[$sidebar_id])) {
     if($sidebar_id == $val) {
      $output .= " selected='selected'";
    }
    $output .= " value="".$sidebar_id."">".$sidebar['name']."</option>";
  }
}
$output .= "</select>";