Skip to content

How to set select option value dynamically in PHP?

foreach($optionArr as $key => $value){
   $isSelected =""; //added this line
   if($_REQUEST['opt_side_'.$cside] == $value){
     $isSelected = "selected";
   echo '<option value="'.$value.'"'.$isSelected.'>'.$key.'</option>';


$optionArr = array ('Available' => 'Available', 'Not Available' => 'Not Available',  'Sold Out' => 'Sold Out',);
<select id="{{ $eventPrice->id }}" class="drop form-control">
  @foreach ($optionArr as $key =>$value)
    @if ( $eventPrice->status == $value)
    	<option value="{{$value}}" class="" selected>{{$key}}</option>
    	<option value="{{$value}}" class="">{{$key}}</option>
See also  CSS code snippet - How to override material ui ?

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.