how to set select option value dynamically in php

Solutions on MaxInterview for how to set select option value dynamically in php by the best coders in the world

showing results for - "how to set select option value dynamically in php"
Emmanuel
12 Jan 2021
1foreach($optionArr as $key => $value){
2   $isSelected =""; //added this line
3   if($_REQUEST['opt_side_'.$cside] == $value){
4     $isSelected = "selected";
5   }
6   echo '<option value="'.$value.'"'.$isSelected.'>'.$key.'</option>';
7}
8
9
10//Laravel
11
12@php
13$optionArr = array ('Available' => 'Available', 'Not Available' => 'Not Available',  'Sold Out' => 'Sold Out',);
14@endphp
15<select id="{{ $eventPrice->id }}" class="drop form-control">
16  @foreach ($optionArr as $key =>$value)
17    @if ( $eventPrice->status == $value)
18    	<option value="{{$value}}" class="" selected>{{$key}}</option>
19    @else
20    	<option value="{{$value}}" class="">{{$key}}</option>
21    @endif
22  @endforeach
23</select>