Why my if-statement not checking each array inside foreach ? If someone already choose same kind of value, I want to disable it from select2 value, here's my code looks like :
function get_status_cab()
{
$status=$_POST['search'];
echo '<label for="username" class="col-sm-3 control-label">Status</label>';
echo '<div class="col-sm-9">';
echo '<select class="form-control select2" name="status">';
$cek=$this->db_umum->select("SELECT id,status FROM lembaga where id='$status'");
foreach($cek as $cek){
$statusnya = $cek->status;
}
$hasil=array(
"pusat" => "Pusat",
"cabang" => "Cabang",
"unit" => "Unit",
"proyek" => "Proyek",
"subproyek" => "Subproyek"
);
foreach($hasil as $value => $label)
{
$no=0;
if($value = $statusnya){
$disable[] = "disabled='disabled'";
}else{
$disable[] = "";
}
echo "<option value='".$value."' $disable[$no]>".$label."</option>";
$no++;
}
echo '</select></div><br/>';
}
The result is if $value = $statusnya , my whole select2 will disabled. But, It is not what I want. I want only value which is exact with $statusnya is disabled and the other is available. Any advice ?