我有两个数组:
$a = array (
[0] => 0
[1] => 1
[2] => 2
[3] => 3
)
$b = array (
[0] => 2
[1] => 1
[2] => 3
[3] => 4
)
如果我想计算同一个对象,我可以使用array_intersect
- > echo count(array_intersect($a,$b));
。
哪个返回:3
但是,我想排除它们相同的行:
$a = array (
[0] => 0
[1] => 1 //Both are the same that I would like to exclude
[2] => 2
[3] => 3
)
$b = array (
[0] => 2
[1] => 1 //Both are the same that I would like to exclude
[2] => 3
[3] => 4
)
只返回2
。
我该怎么做?感谢
答案 0 :(得分:1)
试试这个
$a = array (0,1,2,3);
$b = array (2,1,3,4);
$final = array_unique(array_merge($a,$b));
print "total : ". count($final);
答案 1 :(得分:1)
我会使用一个循环,现在不能想到其他任何东西。
void print_list(void)
{
atom *element;
element = &indeks.head->next;
while (element != &indeks.head) {
// print whatever info
element = element->next;
}
}