Aar*_*ron 1 php oop shuffle function
为什么不对数组进行洗牌,以便每次得到随机结果?
class greeting {
public $greet = array('hi','hello');
shuffle($greet);
}
$hi = new greeting;
echo $hi->greet[1];
Run Code Online (Sandbox Code Playgroud)
我的代码有问题吗?
如果你改变它所以shuffle在构造函数内部它应该工作正常.
class greeting {
public $greet = array('hi','hello');
function __construct(){
shuffle($this->greet);
}
}
Run Code Online (Sandbox Code Playgroud)