我有以下代码
foreach($reportsResult->getRecords() as $key => $reportRecord){
$input = array($reportRecord->getField('Term').' - '.$reportRecord->getField('Year'));
$result = array_unique($input);
print_r($result);
}
这正在产生类似的输出
Array ( [0] => Winter - 2010 )
Array ( [0] => Winter - 2010 )
Array ( [0] => Winter - 2010 )
Array ( [0] => Winter - 2010 )
Array ( [0] => Winter - 2010 )
Array ( [0] => Winter - 2010 )
Array ( [0] => Winter - 2010 )
Array ( [0] => Winter - 2010 )
Array ( [0] => Winter - 2010 )
Array ( [0] => Spring - 2011 )
Array ( [0] => Spring - 2011 )
Array ( [0] => Spring - 2011 )
Array ( [0] => Spring - 2011 )
Array ( [0] => Spring - 2011 )
Array ( [0] => Spring - 2011 )
Array ( [0] => Spring - 2011 )
Array ( [0] => Spring - 2011 )
Array ( [0] => Spring - 2011 )
Array ( [0] => Summer - 2011 )
Array ( [0] => Summer - 2011 )
Array ( [0] => Summer - 2011 )
Array ( [0] => Summer - 2011 )
Array ( [0] => Summer - 2011 )
Array ( [0] => Summer - 2011 )
Array ( [0] => Summer - 2011 )
我想做的只是获得独特的价值,在这种情况下,冬季 - 2010 年,2011 年春季,2011 年夏季。
有人可以建议我如何做到这一点,我认为array_unique
可能是解决方案,但我猜它是值存储在数组中的方式?