我已經寫了下面的函數,它需要一個2維數組並返回一個鍵發生的次數,但感覺就像我可能在這裏重新發明輪子,有沒有簡單的方法?數組中的鍵
function countKeys($array, $key)
{
$results = array();
foreach($array as $row)
{
if (array_key_exists($row[$key], $results))
{
$results[$row[$key]] += 1;
}
else
{
$results[$row[$key]] = 1;
}
}
return $results;
}
我已更新我的答案。它有點清潔,可能對您有所幫助。 –