我有这个片段:
$tableau = array_intersect(GetSearchByRegion($_SESSION['region']),
GetSearchByCity($_SESSION['city']),
GetSearchByState($_SESSION['state']),
GetSearchByCountry($_SESSION['country']),
GetSearchByKeywords($_SESSION['keywords']),
GetSearchByDate($_SESSION['date']),
GetSearchByCompany($_SESSION['company']),
GetSearchByCategory($_SESSION['category']));
if(sizeof($tableau) == 0)
{
header('Location: fail.html');
}
else
{
$tableau1 = array_intersect(GetSearchByRegion($_SESSION['region']),
GetSearchByState($_SESSION['state']));
echo "size of state =".sizeof(GetSearchByState($_SESSION['state']))."</br>";
echo "size total".sizeof($tableau)."</br>";
echo sizeof($tableau1)."</br>";
// $_SESSION['liste'] =GetInformationsFromId($tableau);
// header('Location: list.php');
}
问题是结果是size of state =1
size total3
3
我不知道为什么交叉点不起作用:一个大小= 1的表在另一个表中,结果通常是一个表,它的大小是au max等于one.so:
答案 0 :(得分:2)
Array_intersect()不会消除重复:
php > $x = array('a', 'a', 'b', 'c');
php > $y = array('a', 'b');
php > var_dump(array_intersect($x, $y));
array(3) {
[0]=>
string(1) "a"
[1]=>
string(1) "a"
[2]=>
string(1) "b"
}
php >
请注意a
数组中重复的$x
值。两者之间只有两个不同的共同值,$y
中只有两个值,但交点仍为3个值。
答案 1 :(得分:0)
这是结果: `
table state =
array
0 =>
array
0 => string '1' (length=1)
'id' => string '1' (length=1)
1 => string '2013-01-01' (length=10)
'date' => string '2013-01-01' (length=10)
2 => string 'software engineer' (length=17)
'title' => string 'software engineer' (length=17)
3 => string 'wall street' (length=11)
'state' => string 'wall street' (length=11)
4 => string 'Newyork' (length=7)
'city' => string 'Newyork' (length=7)
5 => string 'alaska' (length=6)
'region' => string 'alaska' (length=6)
6 => string 'quality' (length=7)
'company_name' => string 'quality' (length=7)
table total=
array
0 =>
array
0 => string '1' (length=1)
'id' => string '1' (length=1)
1 => string '2013-01-01' (length=10)
'date' => string '2013-01-01' (length=10)
2 => string 'software engineer' (length=17)
'title' => string 'software engineer' (length=17)
3 => string 'wall street' (length=11)
'state' => string 'wall street' (length=11)
4 => string 'Newyork' (length=7)
'city' => string 'Newyork' (length=7)
5 => string 'alaska' (length=6)
'region' => string 'alaska' (length=6)
6 => string 'quality' (length=7)
'company_name' => string 'quality' (length=7)
1 =>
array
0 => string '2' (length=1)
'id' => string '2' (length=1)
1 => string '2013-01-08' (length=10)
'date' => string '2013-01-08' (length=10)
2 => string 'formater' (length=8)
'title' => string 'formater' (length=8)
3 => string 'erer' (length=4)
'state' => string 'erer' (length=4)
4 => string 'vvv' (length=3)
'city' => string 'vvv' (length=3)
5 => string 'colorado' (length=8)
'region' => string 'colorado' (length=8)
6 => string 'quality' (length=7)
'company_name' => string 'quality' (length=7)
2 =>
array
0 => string '3' (length=1)
'id' => string '3' (length=1)
1 => string '2013-01-08' (length=10)
'date' => string '2013-01-08' (length=10)
2 => string 'hardware engineer' (length=17)
'title' => string 'hardware engineer' (length=17)
3 => string 'rgjjer' (length=6)
'state' => string 'rgjjer' (length=6)
4 => string 'kjrg' (length=4)
'city' => string 'kjrg' (length=4)
5 => string 'oklahoma' (length=8)
'region' => string 'oklahoma' (length=8)
6 => string 'quality' (length=7)
'company_name' => string 'quality' (length=7)
table small=
array
0 =>
array
0 => string '1' (length=1)
'id' => string '1' (length=1)
1 => string '2013-01-01' (length=10)
'date' => string '2013-01-01' (length=10)
2 => string 'software engineer' (length=17)
'title' => string 'software engineer' (length=17)
3 => string 'wall street' (length=11)
'state' => string 'wall street' (length=11)
4 => string 'Newyork' (length=7)
'city' => string 'Newyork' (length=7)
5 => string 'alaska' (length=6)
'region' => string 'alaska' (length=6)
6 => string 'quality' (length=7)
'company_name' => string 'quality' (length=7)
1 =>
array
0 => string '2' (length=1)
'id' => string '2' (length=1)
1 => string '2013-01-08' (length=10)
'date' => string '2013-01-08' (length=10)
2 => string 'formater' (length=8)
'title' => string 'formater' (length=8)
3 => string 'erer' (length=4)
'state' => string 'erer' (length=4)
4 => string 'vvv' (length=3)
'city' => string 'vvv' (length=3)
5 => string 'colorado' (length=8)
'region' => string 'colorado' (length=8)
6 => string 'quality' (length=7)
'company_name' => string 'quality' (length=7)
2 =>
array
0 => string '3' (length=1)
'id' => string '3' (length=1)
1 => string '2013-01-08' (length=10)
'date' => string '2013-01-08' (length=10)
2 => string 'hardware engineer' (length=17)
'title' => string 'hardware engineer' (length=17)
3 => string 'rgjjer' (length=6)
'state' => string 'rgjjer' (length=6)
4 => string 'kjrg' (length=4)
'city' => string 'kjrg' (length=4)
5 => string 'oklahoma' (length=8)
'region' => string 'oklahoma' (length=8)
6 => string 'quality' (length=7)
'company_name' => string 'quality' (length=7)
`