我正在尝试将常规文本与数组一起回显。我将以下代码基于此处找到的答案,但它不起作用: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>";
}
?>
我正在尝试将常规文本与数组一起回显。我将以下代码基于此处找到的答案,但它不起作用: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>";
}
?>
你在这里做错了很多事情
例子
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);
您可以使用.
明显用于连接的符号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>
<?
}
?>