Answers for "how to set select option value dynamically in php"

PHP
0

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>';
}


//Laravel

@php
$optionArr = array ('Available' => 'Available', 'Not Available' => 'Not Available',  'Sold Out' => 'Sold Out',);
@endphp
<select id="{{ $eventPrice->id }}" class="drop form-control">
  @foreach ($optionArr as $key =>$value)
    @if ( $eventPrice->status == $value)
    	<option value="{{$value}}" class="" selected>{{$key}}</option>
    @else
    	<option value="{{$value}}" class="">{{$key}}</option>
    @endif
  @endforeach
</select>
Posted by: Guest on August-02-2021

Code answers related to "how to set select option value dynamically in php"

Browse Popular Code Answers by Language