我想出来了。这并不像我最初想象的那么复杂。只是需要一个函数来计算和。也许它能更有效,我喜欢任何关于它的想法,但这里是:
$rowColumns = array();
for($i=0;$i<=$count-1;$i++)
{
$currentRow = $rows[$i];
$currentCol = $cols[$i];
//count occurences of columns in row
$colSum = $this->getColumnOccurences($count,$rows,$cols,$currentRow,$currentCol);
$rowColumns[$currentRow][$currentCol] = $colSum;
}
private function getColumnOccurences($count,$rows,$cols,$rowValue,$colValue)
{
$retValue = 0;
for($i=0;$i<=$count-1;$i++)
{
if($rows[$i] == $rowValue && $cols[$i] == $colValue)
{
$retValue = $retValue + 1;
}
}
return $retValue;
}
结果是:
Array (
[11] => Array ( [1] => 2 [2] => 1 )
[12] => Array ( [1] => 1 [2] => 1 )
[13] => Array ( [2] => 1 )
[14] => Array ( [1] => 1 [2] => 1 )
)