在要输出为 echo | 的值内回显PHP

echo inside a value to be outputted as echo | PHP

请问,我们如何将echo放在一个被回显的变量中?

这是代码。

我正在尝试将 values=""$user['firstname']$user['lastname']

while($row = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC)){
$out .= "
<div class='form-group' > <!-- hidden-->
<label for='postedby' class='col-sm-3 control-label'>Posted By</label>
<div class='col-sm-9'>
<input type='text' class='form-control' id='postedby' name='postedby' 
value='$user['firstname'] $user['lastname']' style='text-transform:uppercase;width:90%' >
</div></div>
";
    }

    echo $out;
?>

有办法吗?回声内回声?

试试这个。

$out = '';
while($row = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC)){
$out .= '<div class="form-group" > <!-- hidden-->
<label for="postedby" class="col-sm-3 control-label">Posted By</label>
<div class="col-sm-9">
<input type="text" class="form-control" id="postedby" name="postedby" 
value="'.$user['firstname'].' '.$user['lastname'].'" style="text-transform:uppercase;width:90%">
</div></div>';
    }
    echo $out;

你必须 concat 名字和姓氏。

只需将每个变量括起来,php 将完成其余的工作。

while($row = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC)){ 

    $out .= " <div class='form-group' >
       <!-- hidden--> 
           <label for='postedby' class='col-sm-3 control-label'>Posted By</label>
           <div class='col-sm-9'>
               <input type='text' class='form-control' id='postedby' name='postedby' value='{$user['firstname']} {$user['lastname']}' style='text-transform:uppercase;width:90%' >
           </div>
       </div> ";
} 

echo $out; ?>