我正在试图弄清楚如何使用算法的输出作为findLarge的输入。 算法生成一个我想在findLarge
中处理的数组class CSVParser
{
public $output = NULL;
public $digits = NULL;
public $largest = NULL;
public function __construct($file)
{
if (!file_exists($file)) {
throw new Exception("$file does not exist");
}
$this->contents = file_get_contents($file);
$this->output = array();
$this->digits = array();
$this->largest = array();
}
public function algorithm() {....}
public function findLarge($a)
{
// just push it back so I know it's working
var_export($a); // is NULL
$this->largest = $a; // return NULL
}
}
$parser->algorithm();
$parser->findlarge($input); print_r($parser->largest);
答案 0 :(得分:1)
看起来你只是在寻找:
$parser->findlarge($parser->algorithm());
然而,您可能需要考虑几件事情。
str_getcsv
algorithm
是否可以更好地自行调用findLarge
。看起来这个类有两个相互矛盾的目的。一个是存储数据,另一个是处理数据。您可能想要考虑让algorithm
无状态并具有单独的DO,或者让算法修改实例的状态。