【发布时间】:2017-10-24 06:46:17
【问题描述】:
这是我的代码:
class myclass{
public function index(){
$words = ['word1', 'word2', 'word3'];
$result = sizeof($words);
$condition = in_array($word, $words) || strlen($word) <= 3;
$res = $this->investigate_words( $words, $result, $condition )
}
public function investigate_words($words, $result, $condition)
{
foreach($words as $word){
if($condition){
$result--;
}
}
return $result;
}
}
请关注这一行:
$condition = in_array($word, $words) || strlen($word) <= 3;
在这一行中,$word 尚未声明。它应该是存在于investigate_words() 函数中的循环中的值。无论如何,有什么解决办法吗?
【问题讨论】:
-
你想达到什么目的?
investigate_words逻辑上应该怎么做?
标签: php function parameter-passing