如何在php中打印此返回值? 函数printmsg($string,$type){//type 1=绿色,type 2=红色 如果($type==1)$msg=““$string。””; 如果($type==2)$msg=““$string。””; 返回$msg; } printmsg(“你好”,1); //许多其他代码 印刷品($msg);
我试图让我的返回值打印出来,但它似乎从来没有工作 将函数的返回保存在变量中并打印变量如何如何在php中打印此返回值? 函数printmsg($string,$type){//type 1=绿色,type 2=红色 如果($type==1)$msg=““$string。””; 如果($type==2)$msg=““$string。””; 返回$msg; } printmsg(“你好”,1); //许多其他代码 印刷品($msg);,php,Php,我试图让我的返回值打印出来,但它似乎从来没有工作 将函数的返回保存在变量中并打印变量如何 function printmsg($string,$type) {//type 1 = green, type 2 = red if($type == 1) $msg = "<p style=\"color:#00C5CD\">".$string."</p>"; if($type == 2) $msg = "<p style=\"color:#f7110b\"
function printmsg($string,$type) {//type 1 = green, type 2 = red
if($type == 1) $msg = "<p style=\"color:#00C5CD\">".$string."</p>";
if($type == 2) $msg = "<p style=\"color:#f7110b\">".$string."</p>";
return $msg;
}
printmsg("hello",1);
//lots of other code
print($msg);
函数printmsg($string,$type){//type 1=绿色,type 2=红色
如果($type==1)$msg=““$string。”
”;
如果($type==2)$msg=““$string。”
”;
返回$msg;
}
$msg=printmsg(“你好”,1);
//许多其他代码
印刷品($msg);
只需回显即可
function printmsg($string,$type) {//type 1 = green, type 2 = red
if($type == 1) $msg = "<p style=\"color:#00C5CD\">".$string."</p>";
if($type == 2) $msg = "<p style=\"color:#f7110b\">".$string."</p>";
return $msg;
}
$msg = printmsg("hello",1);
//lots of other code
print($msg);
函数printmsg($string,$type){//type 1=绿色,type 2=红色
如果($type==1)$msg=““$string。”
”;
如果($type==2)$msg=““$string。”
”;
返回$msg;
}
echo printmsg(“你好”,1);
如果要返回某些内容,则必须在某些变量中捕获它。同样在PHP
中,您需要使用echo
打印变量
function printmsg($string,$type) {//type 1 = green, type 2 = red
if($type == 1) $msg = "<p style=\"color:#00C5CD\">".$string."</p>";
if($type == 2) $msg = "<p style=\"color:#f7110b\">".$string."</p>";
return $msg;
}
echo printmsg("hello",1);
函数printmsg($string,$type){//type 1=绿色,type 2=红色
如果($type==1)$msg=““$string。”
”;
如果($type==2)$msg=““$string。”
”;
返回$msg;
}
$msg=printmsg(“你好”,1);
//许多其他代码
echo$msg;
您想要这个:
function printmsg($string,$type) {//type 1 = green, type 2 = red
if($type == 1) $msg = "<p style=\"color:#00C5CD\">".$string."</p>";
if($type == 2) $msg = "<p style=\"color:#f7110b\">".$string."</p>";
return $msg;
}
$msg = printmsg("hello",1);
//lots of other code
echo $msg;
函数printmsg($string,$type){//type 1=绿色,type 2=红色
如果($type==1)$msg=““$string。”
”;
如果($type==2)$msg=““$string。”
”;
返回$msg;
}
$msg=printmsg(“你好”,1)
//许多其他代码
印刷品($msg) 将函数结果指定给变量,然后打印<代码>$variable=printmsg(“你好”,1);回声($变量)或者您可以直接打印它
echo(printmsg(“hello”,1))
。printmsg
中的$msg
仅在printmsg
中可用,他可能会混淆函数中的$msg和函数外的$msg。
function printmsg($string,$type) {//type 1 = green, type 2 = red
if($type == 1) $msg = "<p style=\"color:#00C5CD\">".$string."</p>";
if($type == 2) $msg = "<p style=\"color:#f7110b\">".$string."</p>";
return $msg;