-6

I have a problem in this code. I must have the intersection between tables whose count is more than 0. Then I used the function array_interset() but when I use the condition to count I have a problem in this code:

$iheb1 = 
array_intersect( 
    if(count($tab0)>0) { $tab0, }
    if(count($tab1)>0) { $tab1, }
    if(count($tab2)>0) { $tab2, } 
    if(count($tab3)>0) { $tab3, }
    if(count($tab4)>0) { $tab4, }
    if(count($tab5)>0) { $tab5, }
    if(count($tab6)>0) { $tab6 }
);  
Biffen
  • 6,249
  • 6
  • 28
  • 36
IHEB IHEB
  • 1
  • 3
  • 2
    No, you have many problems with that code. – Jonnix Nov 16 '15 at 14:46
  • 1
    Please revise your code formatting, typos and add a description of *why* your code is not working, and what errors you get. Also, your title is in french, please use a more descriptive, english title – T3 H40 Nov 16 '15 at 14:46
  • 1
    Please have a look here: http://stackoverflow.com/help/how-to-ask – Phate01 Nov 16 '15 at 14:47

1 Answers1

0

There many issues here. The big one being your if statements in the parameters of array_intersect.

Try this:

First add all of the arrays to an array or arrays (i used $full_array).

$array_to_test = array();

foreach($full_array as $arr){
    if(count($arr)>0){
        array_push($array_to_test, $arr);
    }
}
$iheb1 = array_reduce($array_to_test,function(&$a,$b) {$a = array_intersect($a,$b);},Array());

I found a similar question to yours and this seems to be working.

Community
  • 1
  • 1
  • i like to have the intersection just between arrays whitch have length>0 – IHEB IHEB Nov 16 '15 at 15:01
  • It does answer why he is getting an error. When it was posted initially there was not more information as to what the end goal was so this was the only thing to answer. – Lucas Desouza Nov 16 '15 at 15:42
  • i like to determinate the intersection just betwwen table whitch have count >0 – IHEB IHEB Nov 16 '15 at 15:48
  • i used this code $array_to_test = array(); $fullArray = array($tab0,$tab1,$tab2,$tab3,$tab4,$tab5,$tab6,$tab7); foreach($full_array as $arr){ if(count($arr)>0){ array_push($array_to_test, $arr); } } $iheb1 = array_reduce($array_to_test,function(&$a,$b) {$a = array_intersect($a,$b);},Array()); – IHEB IHEB Nov 16 '15 at 16:06
  • we'll need more information than that. Is it giving you an error? What other debugging steps have you gone through to test it out? – Lucas Desouza Nov 16 '15 at 16:23