,结果却有了,同为1000;具体原因是:echo为输出值;return为返回值却不输出,若想有输出需要再次使用echo输出。
<?
class Human{  
private $money = 1000;  
public function showMoney(){    
return $this->money; }}
$money = new Human();
$money->showMoney();
 
?>二、
<?
class Human{  
private $money = 1000;  
public function showMoney(){    
echo $this->money; }}
$money = new Human(); 
$money->showMoney();
?>三、
<?
class Human{  
private $money = 1000;  
public function showMoney(){    
return $this->money; }}
$money = new Human();
echo $money->showMoney();
 
?>echo和return的区别:
——>echo是输出到浏览器,return是终止后面代码的执行并返回一个值。
PHP=>PHP用return,PHP=>浏览器和用echo
| 欢迎光临 一起源码网 (https://www.171739.xyz/) | Powered by Discuz! X3.3 |