三元逻辑php问题

问题描述 投票:-1回答:2

var $ bt_ent包含字母“ V”或“ L”,那么为什么我的td的可见性保持空白?我的三元逻辑不好?

我的代码:

<?php $bt_ent = $this->depotInformation->bt_entite->getValue() ?>
<td style="visibility : <?php $bt_ent = 'V' ? 'visible' : 'hidden'; ?>">
    <div id="poidUnitaire" style="margin:0px 100px 0px 0px;" >

The DevTools:

<td style="visibility : ">
    <div id="poidUnitaire" style="margin:0px 100px 0px 0px;">

谢谢

php syntax ternary
2个回答
1
投票

您正在分配(=)而不是进行比较(==)。也缺少echo来实际输出结果。

<?php $bt_ent = $this->depotInformation->bt_entite->getValue() ?>
<td style="visibility : <?php echo $bt_ent == 'V' ? 'visible' : 'hidden'; ?>">
    <div id="poidUnitaire" style="margin:0px 100px 0px 0px;" >

0
投票

您正在分配$bt_ent而不是打印它。

更改

<?php $bt_ent = 'V' ? 'visible' : 'hidden'; ?>

to

<?php echo ($bt_ent == 'V' ? 'visible' : 'hidden'); ?>

0
投票

您正在分配而不是进行比较。而且回声丢失了。

<?php $bt_ent = $this->depotInformation->bt_entite->getValue() ?>
<td style="visibility : <?php echo $bt_ent == 'V' ? 'visible' : 'hidden'; ?>">
    <div id="poidUnitaire" style="margin:0px 100px 0px 0px;" >
© www.soinside.com 2019 - 2024. All rights reserved.