0

我有这个片段:

$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 等于一个的表。所以:

  • 我需要知道错误是什么
  • 我该如何解决?
4

2 回答 2

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 个值。

于 2013-01-08T21:12:39.397 回答
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)

`

于 2013-01-08T21:51:59.273 回答