问题描述
好的,所以我有一些代码给我适合。调用函数 d($ z);
<$>
$ z本身是代码中其他地方声明的变量。 p $ p> 这样做: 任何想法为何? 虽然这不是我想要做的,但因为我想使用$ distance的结果作为内部变量(而不是回显它),所以如果我做了 有两种可能的(可能更多)问题: 您没有将正确的值传递给函数 或 编辑:不要忘记echo $ value(存储返回) Okay, so I have some code that is giving me fits. To call the function $z itself is a declared variable elsewhere in the code. This doesn't work: This works: Any ideas why? Note: I don't want the value echo'd. I want to be able to use the value later on, as a variable, and not necessarily printed to the screen. (Now, the above is a simplified version, a lot has been removed, of what I really want to do, but even the above doesn't return properly for me) Although it's not what I want to do, since I want to use the result of $distance as an internal variable (not echo it), if I do There are 2 possible (probably more) problems: You are not passing a correct value into the function or You are not assigning the return to a variable (ex. Edit: Don't forget to echo $value (stored return) 这篇关于函数回声与返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!函数d($ x1){
$ distance = $ x1;
返回$ distance;
$ / code>
函数d($ x1){
$ distance = $ x1;
echo $ distance;
}
注意:我不想让这个值回显。我希望能够稍后使用该值作为变量,并且不一定会打印到屏幕上。 (现在,上面是一个简化版本,很多已被删除,我真正想做的事情,但即使上述不会正确返回给我)
<?= $ distance?>< code>它不适用于返回。
$ value = d(some value here);
d($z);
function d($x1){
$distance = $x1;
return $distance;
}
function d($x1){
$distance = $x1;
echo $distance;
}
<?=$distance?>
it doesn't work with the return.$value = d("some value here");
)