我知道print_r
打印数组和对象并echo
完成其余的工作。
我的问题是我编码某些东西的结果,并且以某种方式返回的 a 变量function
不会打印,echo
但它会打印print_r
or var_dump
。我很容易相信这个结果是我的代码的问题,而不是两者之间的差异echo
,print_r
因为返回的变量string
不是array
所以我的问题如下:function showPreviousDiscipline
如果我放入模板,为什么只显示它返回的 HTML 代码print_r
?它不应该只通过我调用函数而不需要echo
or来显示print_r
吗?在一天结束的时候只是文本输出的内容
的HTML
<div class="ldcMainWrap">
<table>
<tr>
<td>
<select multiple="multiple" size="5">
<?php
// Displays something in the page if is print_r but not if i echo it... or even if i dont put anything...
print_r ($this->showPreviousDiscipline(1));
?>
</select>
</td>
<td>
<select multiple="multiple" size="5">
</select>
</td>
<tr>
</table>
<div>
PHP的
public function drawWebsite () {
$tpl = include "step.one.view.php";
return $tpl;
}
public function showPreviousDiscipline ( $uID ) {
$AllUserDetails = parent::$this->pullUserDetails ( $uID );
$allDataRaw = parent::$this->pullDeparmentTableData ();
$html = '';
// Loops through the array $allDataRaw
foreach ($allDataRaw as $key => $val) {
foreach ($val as $key2 => $val2) {
//CHECKs if he user has already selected one and if it does it applies a CSS class
if($key2) {
if($val2 === $AllUserDetails['rID']) {
$html .= '<option value ="'.$val2.'" class="selected">'.$key2.'</option>';
}else {
$html .= '<option value ="'.$val2.'" class="unselected">'.$key2.'</option>';}
}
}
}
$html .= '';
return $html;
}
测试输出
<select multiple="multiple" size="5">
<option value="11" class="unselected">dID</option>
<option value="test1" class="unselected">dName</option>
<option value="" class="unselected">dDescription</option>
<option value="22" class="selected">dID</option>
<option value="test2" class="unselected">dName</option>
<option value="" class="unselected">dDescription</option>
</select>