0

我正在尝试将常规文本与数组一起回显。我将以下代码基于此处找到的答案,但它不起作用: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>";
}
?>
4

2 回答 2

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);
于 2012-10-18T03:02:24.090 回答
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>";
    }
?>

或者你可以分开HTMLPHP像这样:

<?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>      
<?
    }
?>
于 2012-10-18T03:03:29.793 回答