如何從同一個類中的另一個函數中查看變量?如何查看PHP類中另一個類函數的變量?
這裏的問題是我有:
class slike {
public function __construct($dire) {
$this->dire=$dire;
}
function skupljanjeslika() {
$slike = array();
$handler = opendir($this->dire);
while ($file = readdir($handler)) {
if ($file != "." && $file != "..") {
$slike[] = $file;
}
}
closedir($handler);
return $slike; // **Array i want to use!**
}
function prikazradnomslike() {
$slike; // Here is the array from first function, but I can't see it here
$rezultat = count($slike)-1;
$koliko=rand(0, $rezultat);
$slika=$slike[$koliko];
return $slika;
}
}
只要在構建之前添加它,就像你做的那樣? – 2012-07-27 13:42:12
是的,在構造函數之前。 – 2012-07-27 13:42:39