我有3个变量垫,跟随,不是 如果任何变量具有值,那么只有一个可以一次拥有我想要的值,它应该在msg中更新
这是我的逻辑
<?php
$mat = $this->input->post('mater_mesaage') ;
$folow = $this->input->post('follow_message') ;
$not = $this->input->post('not_inst_comment') ;
if (isset($mat)){
echo "Mat";
$msg = $mat ;
}
if (isset($folow )) {
echo "folow" ;
$msg = $folow ;
}
if (isset($not)){
echo "not" ;
$msg = $not ;
}
echo $msg ;
?>
答案 0 :(得分:1)
请将==
替换为=
<?php
$mat = $this->input->post('mater_mesaage') ;
$folow = $this->input->post('follow_message') ;
$not = $this->input->post('not_inst_comment') ;
if (isset($mat)){
echo "Mat" ;
$msg = $mat ;
}
if (isset($folow )) {
echo "folow" ;
$msg = $folow ;
}
if (isset($not)){
echo "not" ;
$msg = $not ;
}
echo $msg ;
?>
答案 1 :(得分:0)
一次只有一个值,所以你应该使用elseif
,所以你去了:
<?php
$mat = $this->input->post('mater_mesaage') ;
$folow = $this->input->post('follow_message') ;
$not = $this->input->post('not_inst_comment') ;
if (isset($mat)){
echo "Mat";
$msg == $mat;
}elseif (isset($folow )) {
echo "folow";
$msg == $folow;
}else{
echo "not";
$msg == $not;
}
echo $msg;
?>
答案 2 :(得分:0)
<?php
$mat = $this->input->post('mater_mesaage');
$folow = $this->input->post('follow_message');
$not = $this->input->post('not_inst_comment');
if ($mat != '' || $folow != '' || $not != '') {
$msg = ($mat != '') ? $mat : (($folow != '') ? $follow : $not);
}
?>