如何在Php中显示我的输出,并在循环中返回?
我想输出我的代码。当我使用return时,它会在1次和之后崩溃 (当我使用echo时,我的内容将显示在页面顶部。我认为我不应该在这里使用echo,因为我想稍后调用循环中的函数) 以下图片将显示它的外观: 我的返回代码:如何在Php中显示我的输出,并在循环中返回?,php,wordpress,Php,Wordpress,我想输出我的代码。当我使用return时,它会在1次和之后崩溃 (当我使用echo时,我的内容将显示在页面顶部。我认为我不应该在这里使用echo,因为我想稍后调用循环中的函数) 以下图片将显示它的外观: 我的返回代码: function allmyshortcodesloopfunction() { $alltheshortcodes = ''; $alltheshortcodes = 'thistextshouldbehere4times'; for($i=0; $i
function allmyshortcodesloopfunction() {
$alltheshortcodes = '';
$alltheshortcodes = 'thistextshouldbehere4times';
for($i=0; $i < 4; $i++) {
echo '<p></p>';
return $alltheshortcodes;
}
}
function allmyshortcodesloopfunction(){
$alltheshortcodes='';
$alltheshortcodes='ThisTextshouldbehere4次';
对于($i=0;$i<4;$i++){
回声“”;
返回$alltheshortcodes;
}
}
这看起来怎么样:
echo的外观:
也许你可以发布一个我找不到的线程来解决这个问题。
一些标签用于将来出现此问题的人。他们可以找到:
循环,while,if,return,statement,content,分解,仅一次,仅一次{
function allmyshortcodesloopfunction() {
$alltheshortcodes = 'thistextshouldbehere4times';
for ($i = 0; $i < 4; $i++) {
echo "<p>$alltheshortcodes</p>";
}
}
allmyshortcodesloopfunction();
$alltheshortcodes='ThisTextshouldbehere4次';
对于($i=0;$i<4;$i++){
echo“$alltheshortcodes”;
}
}
AllMyShortCodeLoopFunction();
Return退出函数,不能将其包含在循环中。单独存储它,然后重用该函数
function allmyshortcodesloopfunction() {
$output = '';
$alltheshortcodes = 'thistextshouldbehere4times';
for ($i=0; $i < 4; $i++) {
$output .= "<p>$alltheshortcodes</p>";
}
return $output;
}
function allmyshortcodesloopfunction(){
$output='';
$alltheshortcodes='ThisTextshouldbehere4次';
对于($i=0;$i<4;$i++){
$output.=“$ALL THESHORTCODE”;
}
返回$output;
}
谢谢。我做了一些不同的操作:函数allmyshortcodesloopfunction(){$alltheshortcodes='';$alltheshortcodes='thistextshouldbehere4times';对于($i=0;$i<4;$i++){$output.='hi';}返回$output;}代码型答案在stackoverflow上的价值很低,因为它们对未来数千名研究人员的教育/授权作用甚微。