无法返回两个变量。虽然,您 可以 传播一个数组并返回它;创建条件以返回动态变量,等等。
例如,此函数将返回
$var2
function wtf($blahblah = true) { $var1 = "ONe"; $var2 = "tWo"; if($blahblah === true) { return $var2; } return $var1;}
在应用中:
echo wtf();//would echo: tWoecho wtf("not true, this is false");//would echo: ONe
如果您都想要它们,可以稍微修改一下功能
function wtf($blahblah = true) { $var1 = "ONe"; $var2 = "tWo"; if($blahblah === true) { return $var2; } if($blahblah == "both") { return array($var1, $var2); } return $var1;}echo wtf("both")[0]//would echo: oneecho wtf("both")[1]//would echo: tWolist($first, $second) = wtf("both")// value of $first would be $var1, value of $second would be $var2
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)