PHP在html中操作select?

I am trying to manipulate my html select function through PHP. and I can't concatenate my PHP with html

What I am doing: When I select a drop down function it load the option of the selected field.

Problem: When I load the field the option that I chose get unselected.

what I am doing: So what I am doing is pass a If statement to check it is true or not.

This is my code:

$result.='    
<div class="form-group">
  <label class="col-sm-2 control-label">Expenses Type:</label>

    <div class="col-sm-4" >
      <select name="expenses" style="width:285px;" class="form-control" onchange="submit(this.value)"  >
        <option value="0" selected="selected">Select Type</option>
        <option value="3" '.if($expenses==3) {.' selected="selected" '.}.'>Other Expenses</option> /*this is the line of error*/
        <option value="4" >Salary</option>
      </select>
    </div>
</div>';

Someone tell me to use ternary expression but I don't know how.

Just try with:

$result .= ' ....

    <option value="3" ' . ($expenses==3 ? ' selected="selected" ' : '') . '>Other Expenses</option>

    ... ';

youshould change it to:

 <div class="form-group">
     <label class="col-sm-2 control-label">Expenses Type:</label>
     <div class="col-sm-4" >
      <select name="expenses" style="width:285px;" class="form-control" onchange="submit(this.value)"  >
        <option value="0" > Select Type</option>
        <option value="3" <?php if($expenses==3) echo 'selected="selected"' ?> >Other Expenses</option>  
        <option value="4" <?php if($expenses==4) echo 'selected="selected"' ?> >Salary</option>
      </select>
    </div>
 </div>

By default the first value is selected you dont have to use a check there because if none of the other is selected the first should be selected

Post as less as possible php in your html. i changed it to html instead of php and only on the places i want the actual check i use the php.