0

Why it always show only the condition of single my data is married but it didn`t follow my condition this is my code

 $civil = $rowpatient['civil'];
              if ($civil = "Single") {
                 # code...
                ?> <select class='form-control' required name='civil'>
                                     <option>Single</option>
                                     <option>Married</option>
                                     <option>Widowed</option>
                                 </select>
                                 <?php
             }elseif ($civil = "Married") {
                 # code...
               ?> <select class='form-control' required name='civil'>
                                     <option>Married</option>
                                     <option>Widowed</option>
                                     <option>Single</option>
                                 </select> <?php
             }elseif ($civil = "Widowed") {
                 # code...
                ?>
                <select class='form-control' required name='civil'>
                                     <option>Widowed</option>
                                     <option>Married</option>
                                     <option>Single</option>
                                 </select>
                                 <?php
             }
             ?>

1 Answers1

-2

The '=' is an assignment operator and will be used to assign values to the variables.

$a = 10;

This means store 10 into variable $a;

$a = 20;  
$b = $a;       

The above example means first store 20 into variable $a and then store the variable $a into $b. Since $a is 20 and it is being assigned to $b then automatically $b also becomes 20.

Let's come down to the "==". That's the equality operator. It is used to check whether two values are same.

$a = 30;
$b = 30;
if ($a == $b){
    // do something if both are equal
}

The comparison uses "==", checking if $a has the same value as of $b. It's not as precise as "===" (also compares the variable type), but for most uses, "==" is sufficient.

There are a few other operators also, have a look at the documentation: http://php.net/manual/en/language.operators.comparison.php

dearsina
  • 4,774
  • 2
  • 28
  • 34