我正在尝试将常规文本与数组一起回显。我将以下代码基于此处找到的答案,但它不起作用:Echo arrays with regular text
<?php
$val1 = Yes;
if (($row->relation) == ($val1)) {
echo "<p><b>Applicant\'s Name:</b> {$row['relation_name']} | <b>Business:</b> {$row['relation_business']}</p>";
}
?>
答案 0 :(得分:1)
你这么做了很多错事
示例
V--------------------- Row Seems to be Object here
if (($row->relation) == ($val1)) {
echo "<p><b>Applicant\'s Name:</b> {$row['relation_name']}
^---------------------- Calling it as array here
在您澄清上述内容后,您可以使用printf
代替
如果是array
:
printf("<p><b>Applicant\'s Name:</b> %s|<b>Business:</b>%s</p>",$row['relation_name'],$row['relation_business']);
如果是Object
printf("<p><b>Applicant\'s Name:</b>%s|<b>Business:</b>%s</p>",$row->relation_name,$row->relation_business);
答案 1 :(得分:1)
您可以使用明确用于.
中连接的php
符号:
<?php
$val1 = Yes;
if (($row->relation) == ($val1)) {
echo "<p><b>Applicant\'s Name:</b>" . $row['relation_name'] . | . "<b>Business:</b>" . $row['relation_business'] . "</p>";
}
?>
或者你可以像这样分开HTML
和PHP
:
<?php
$val1 = Yes;
if (($row->relation) == ($val1)) {
?>
<p><b>Applicant\'s Name:</b><?php echo $row['relation_name'] ?>|<b>Business:</b><?php echo $row['relation_business'] ?></p>
<?
}
?>