我試圖從內部算法訪問GCD,但它不讓我,我不知道爲什麼。我在這裏做錯了什麼?從另一個方法內部訪問方法
public function gcd($x,$y)
{
do {
$rest=$x%$y;
$x=$y;
$y=$rest;
} while($rest!==0);
return $x;
}
public function algorithm()
{
$alpha = array(
'c' => str_split('bcdfghjklmnpqrstvwxz'),
'v' => str_split('aeiouy')
);
$i=$k=0;
foreach ($this->output as $item) {
$cnt = 0;
$this->digits[$i] = array();
foreach ($item as $part) {
$this->digits[$i][$cnt] = array();
$new = array();
foreach ($part as $str) {
$v = count(array_intersect(str_split($str), $alpha['v']));
$c = count(array_intersect(str_split($str), $alpha['c']));
$t = strlen(str_replace(' ', '', $str));
$new = ($cnt == 0)
? array('v' => $v, 'c' => $c, 't' => $t, 'm' => ($t%2) ? $v * 1.5 : $c)
: array('v' => $v, 'c' => $c, 't' => $t);
$this->digits[$i][$cnt][] = $new;
}
$cnt++;
}
$i++;
}
$h=$a=0;
foreach($this->digits as &$etc) {
foreach($etc[0] as &$r){
foreach($etc[1] as $k) {
foreach($k as $x=>$y) {
$tmp[$h] = (gcd($y,$r['t']) != 1) ? ++$a:'';
}
$tmp[$h] = $r['m']*$a*1.5;
$h++;
$a=0;
}$h=0;
$r['f'] = $tmp;
$tmp='';
}
}
foreach($this->digits as &$u){unset($u[1]);}
}
爲了更快更好地回答問題,儘可能多地刪除不相關的代碼,並清楚地指出哪條線路會導致錯誤。 (最重要的是,它會表明你自己做了一些努力) – xtofl