Search
 
SCRIPT & CODE EXAMPLE
 

PHP

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>
Comment

PREVIOUS NEXT
Code Example
Php :: doctrine querybuilder select alias 
Php :: wordpress custom post type query 
Php :: how to pass token with post request laravel 
Php :: function passing multiple arguments using 3 dots php 
Php :: laravel db table get one columns value 
Php :: php catch echo output 
Php :: date_default_timezone_set php bangladesh 
Php :: laravel create controller 
Php :: laravel select raw where 
Php :: Converting timestamp to time ago in PHP 
Php :: a php session was created by a session_start() 
Php :: convert datetime to string in php 
Php :: remove colon and white space in a string by php 
Php :: laravel capsule schema datatime CURRENT_TIMESTAMP 
Php :: create custom header in wordpress 
Php :: how to write orderby in join query with where clause in codeigniter 
Php :: laravel get route parameters in blade 
Php :: The media must not be greater than 12288 kilobytes in laravel 
Php :: get data from another table laravel 
Php :: php append n time pattern to string 
Php :: php get slug 
Php :: wordpress widget current year 
Php :: url segment laravel 
Php :: laravel create on model 
Php :: remove more than one space in string php 
Php :: carbon add and subtract 
Php :: laravel model::query 
Php :: Arr::only laravel 
Php :: laravel validation required if 
Php :: laravel documentation updateOrCreate 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =