-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 }
);  
3
  • 2
    No, you have many problems with that code. Commented Nov 16, 2015 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 Commented Nov 16, 2015 at 14:46
  • 1
    Please have a look here: stackoverflow.com/help/how-to-ask Commented Nov 16, 2015 at 14:47

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

5 Comments

i like to have the intersection just between arrays whitch have length>0
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.
i like to determinate the intersection just betwwen table whitch have count >0
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());
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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.