在 HTML 中访问 php 数组元素

康滕班

我在 php 中有这个:

'position' => [
			'label' => ['Pic Position', ''],
			'inputType' => 'select',
			#'default' => 'left',
			'options' => [
				'left' => 'Left',
				'right' => 'Right',
			],
		]

现在我想要如果选择了“左”,那么一个名为左的类被添加到一个 div 中!我无法弄清楚 php 语法!

<div class="floating_text" <?php if ($this->position == 'left') echo 'class="left"' ?>>
		<?= $this->text ?>
	</div>

这显然是错误的!

戴夫

将您的 PHP 条件移至现有条件,class=而不是尝试创建另一个class=错误的实例

<div class="floating_text <?php echo ($this->position == 'left') ? 'left' : '' ?>">
        <?= $this->text ?>
</div>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章