title: How to print the value that is selected in dropdown list in PHP or set it as selected?
body: <p>I want to set the value to selected that has been selected in dropdown list and also want to print that value that has been submitted in that form.</p>
  
  <p>When i print print_r[$value]; 
  i just get some values.</p>
  
  <p>Below is my code:</p>
  
  <pre><code>      &lt;form method="post" action="" id="date_date" name="date_data"&gt;
  
              &lt;div class="col-sm-4"&gt;
                &lt;h3&gt;&lt;label for="sel1"&gt;Select From Date:&lt;/label&gt;&lt;/h3&gt;
                &lt;h3&gt;&lt;?php echo $this-&gt;input-&gt;post('date_data');?&gt;&lt;/h3&gt;
                &lt;input type="text" id="datepicker" name="date_data"&gt;
              &lt;/div&gt;
  
              &lt;div class="col-sm-4"&gt;
                &lt;h3&gt;&lt;label for="sel1"&gt;Select To Date:&lt;/label&gt;&lt;/h3&gt;
                &lt;h3&gt;&lt;?php echo $this-&gt;input-&gt;post('to_data');?&gt;&lt;/h3&gt;
                &lt;input type="text" id="datepicker_to" name="to_data"&gt;
              &lt;/div&gt;
              &lt;div class="col-sm-4"&gt;
  
              &lt;?php
              $user_type = $this-&gt;session-&gt;userdata('user_type');
  
              if($user_type =="admin")
  
              {
              ?&gt;
              &lt;div class="form-group"&gt;
  
                  &lt;h3&gt;&lt;label for="sel1"&gt;Select Employoee Name:&lt;/label&gt;&lt;/h3&gt;
                  &lt;select name="attendance-list" id="attendance-list" class="form-control" &gt;
  
  
  
  
                    &lt;?php foreach($attendance_dropdown as $value)
              { 
             ?&gt;
  
              &lt;option id="emp" value="&lt;?php echo $value['emp_id'];?&gt;"&gt;&lt;?php echo $value['emp_name'];?&gt;&lt;/option&gt;
              $dropdown = str_replace("value='".$rid."'","value='".$rid."' selected=\"selected\"",$dropdown);
          &lt;?php
  
            } 
            ?&gt;
  
                  &lt;/select&gt;
  
  
                  &lt;?php echo "&lt;br&gt;"; ?&gt;
  
              &lt;/div&gt;
            &lt;?php  
              }
  
  
              else
              {
              ?&gt;
              &lt;div class="form-group"&gt;
  
                  &lt;input type="hidden" name="attendance-list" value="&lt;?php echo $this-&gt;session-&gt;userdata('emp_id'); ?&gt;"&gt;
  
              &lt;/div&gt;
  
             &lt;?php
  
  
              }
              ?&gt;
           &lt;/div&gt; &lt;!--Col-sm-8--&gt;
           &lt;div class="col-sm-4"&gt;
            &lt;h3&gt;&lt;label for="sel1"&gt;&lt;/label&gt;&lt;/h3&gt;
            &lt;input type="submit" value="submit" class="btn btn-primary"&gt;
          &lt;/div&gt;
  
      &lt;/form&gt;
  </code></pre>