there are two arrays first

$idCountmfilmr array(5) { [0]=> int(5) [1]=> int(8) [2]=> int(9) [3]=> int(17) [4]=> int(18) } 

second

 $idCountmfilmi array(26) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(4) [4]=> int(6) [5]=> int(7) } 

I get these two arrays like this

 if ($countr == 1) {if (is_array($idSer)) { ... $idCountmfilmr = array_intersect($idSer, array_column($idCounmfilm, 'id')); } else { $idCountmfilmr = array_column($idCounmfilm, 'id'); } } if ($countr == 0){ ... if (is_array($idSer)) { $idCountmfilmi = array_intersect($idSer, array_column($idCounmfilm, 'id')); } else { $idCountmfilmi = array_column($idCounmfilm, 'id'); } 

trying to merge

 $idCountmfilm=array_merge($idCountmfilmr,$idCountmfilmi); 

so getting

  array(5) { [0]=> int(5) [1]=> int(8) [2]=> int(9) [3]=> int(17) [4]=> int(18) } array(26) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(4) [4]=> int(6) [5]=> int(7) [6]=> int(10)} 

tried to organize so

 $idCountmfilm=array(); if ($countr == 1) {if (is_array($idSer)) { ... array_push($idCountmfilm,array_intersect($idSer, array_column($idCounmfilm, 'id'))); } else { array_push($idCountmfilm,array_column($idCounmfilm, 'id')); } } if ($countr == 0){ ... if (is_array($idSer)) { array_push($idCountmfilm,array_intersect($idSer, array_column($idCounmfilm, 'id'))); } else { array_push($idCountmfilm,array_column($idCounmfilm, 'id')); } 

getting

 array(1) { [0]=> array(7) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(4) [4]=> int(6) [5]=> int(7) [6]=> int(10)}} 

I would like to receive

 array(11) { [0]=> int(5) [1]=> int(8) [2]=> int(9) [3]=> int(17) [4]=> int(18) [5]=> int(2) [6]=> int(3) [7]=> int(4) [8]=> int(6) [9]=> int(7) [10]=> int(10) } 

    1 answer 1

    Try this:

     $idCountmfilmr = array(5, 8, 9, 17, 18); $idCountmfilmi = array(1, 2, 3, 4, 6, 7); for ($i=1; $i<6; $i++){ $idCountmfilmr[] = $idCountmfilmi[$i]; } 

    The result will be: array(10) { [0]=> int(5) [1]=> int(8) [2]=> int(9) [3]=> int(17) [4]=> int(18) [5]=> int(2) [6]=> int(3) [7]=> int(4) [8]=> int(6) [9]=> int(7) }

    • array (5) {[0] => int (5) [1] => int (8) [2] => int (9) [3] => int (17) [4] => int (18) } array (7) {[0] => int (2) [1] => int (3) [2] => int (4) [3] => int (6) [4] => int (7 ) [5] => int (10) [6] => int (11)} - Sergalas
    • Changed the answer. Try to do by analogy, should work that way. You simply iterate through the $ idCountmfilmi array by indices (not counting zero), add the values ​​from $ idCountmfilmi to the end of the $ idCountmfilmr array. In the loop, you specify $ i <the maximum index of the $ idCountmfilmi array. - Kernel Panic
    • And what is the essential difference between the first version and this? - Sergalas
    • there the condition was slightly different. Did not consider the zero index. It is necessary to compare $ i with the maximum array index, and I first wrote what is needed with the maximum +1. - Kernel Panic
    • Here is the previous option for ($ i = 1; $ i <count ($ idCountmfilmi); $ i ++) {$ idCountmfilmr [] = $ idCountmfilmi [$ i]; } var_dump ($ idCountmfilmr); except that I added count ($ idCountmfilmi) when calculating the length of the array. What is the difference? - Sergalas