我的人一個數組,看起來像這樣:計數的值在一個陣列出現在另一個陣列的出現
$people =
Array
(
[0] => Array
(
[email] => [email protected]
[name] => Name Surname
[count] => 0
)
[1] => Array
(
[email] => [email protected]
[name] => Name2 Surname
[count] => 0
)
)
而且我有一個數組這是一個MySQL查詢,查找的結果像這樣:
$query=
Array
(
[0] => Array
(
[email] => [email protected]
[name] => Name Surname
)
[1] => Array
(
[email] => [email protected]
[name] => Name2 Surname
)
[2] => Array
(
[email] => [email protected]
[name] => Name Surname
)
)
對於$每個人的e-mail地址,我想$people['count']
等於該E-mail地址在$查詢多少次發生。
我試過的方式來做到這一點的負載,而且我不太得到期望的結果。
爲免生疑問,我的最終結果根據上面的例子應該是這樣的:
$people =
Array
(
[0] => Array
(
[email] => [email protected]
[name] => Name Surname
[count] => 2
)
[1] => Array
(
[email] => [email protected]
[name] => Name2 Surname
[count] => 1
)
)
其中是您檢查重複值的代碼。 – greatmajestics 2012-08-12 11:36:49
您可以直接從數據庫中選擇計數的電子郵件嗎?類似這樣的: 'SELECT count(*)FROM table WHERE email IN('[email protected]','[email protected]')GROUP BY email'? – 2012-08-12 11:37:46
我明白你在說什麼,但在這個特殊情況下,這兩者都沒有用。數組實際上包含比上面顯示的更多的信息,因此重複值不是問題。至於MySQL查詢,每個數組可能包含數百個項目,因此任何額外的查詢都不是最佳的。感謝您花時間評論 – SpongeBobPHPPants 2012-08-12 11:41:59