Need an Array Count On Common Values
I am Using PHP and Mysql, Apachhe
I Have an Array
Array
(
[2] => Array
(
[0] => 6
[1] => 2
)
[1] => Array
(
[0] => 6
[1] => 2
)
)
Here The middle container is the Document ID and the final child开发者_Go百科ren are userids, Here I am looking for a way to find a method to count the common user ids among all the different Documents. I also need it specified that a particular user id available in which documentids...
could Some one guide me to achieve this?
Thanks in Advance, OM
$unique_users = array();
foreach ($docs as $doc_id => $users)
{
foreach ($users as $user_id)
{
if (!isset($unique_users[$user_id]))
$unique_users[$user_id] = array($doc_id);
else
$unique_users[$user_id][] = $doc_id;
}
}
echo count($unique_users); // number of users
var_dump($unique_users[1]); // list of documents user_id #1 is in
Add all the ids from the first element to an array. Then continue to loop through the other elements and keep only the ids that are also in the current element.
精彩评论