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が1に等しいテーブルです.so:

  • 私はエラーが何であるかを知る必要があります
  • どうすれば修正できますか?
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した値に注意してください。$x2つの間に共通する2つの異なる値、およびの2つの値のみです$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 に答える