I will combine the following array: This array will be combined with itself
Array (
[0] => Array
(
[0] => 1
[1] => 2
)
[1] => Array
(
[0] => 1
[1] => 3
)
[2] => Array
(
[0] => 1
[1] => 4
)
[3] => Array
(
[0] => 2
[1] => 3
)
[4] => Array
(
[0] => 2
[1] => 4
)
[5] => Array
(
[0] => 3
[1] => 4
)
);
after combined will produce an array like this:
Array (
[0] => Array
(
[0] => 1
[1] => 2
[2] => 3
)
[1] => Array
(
[0] => 1
[1] => 2
[2] => 4
)
[2] => Array
(
[0] => 2
[1] => 3
[2] => 4
)
);
for example, from 1.2 combined with 1.3 will produce 1,2,3 or from 1,2 with 1,4 = 1,2,4
Hopefully you want to like this. So you need to check condition which index array concatenate and that index don't check to push value
$my_Arr = array(
array(1,2),
array(1,3),
array(1,4),
array(2,3),
array(2,4),
array(3,4)
);
echo "<pre>";
print_r($my_Arr);
echo " ------------------------- <br> ";
$elements = sizeof($my_Arr);
$first_num = '';
$second_num = '';
for ($i=0; $i < $elements; $i++) {
$subelements = sizeof($my_Arr[$i]);
if($subelements < 4){
for ($j=0; $j < $subelements ; $j++) {
if($j == 0 ){
$first_num =$my_Arr[$i][$j];
}
if($j == 1 ){
$second_num =$my_Arr[$i][$j];
}
if($first_num !=null && $second_num != null){
for ($k=0; $k < $elements; $k++) {
for ($l=0; $l < $subelements ; $l++) {
if($first_num == $my_Arr[$k][$l] && $second_num!=$my_Arr[$k][$l+1]){
if (!in_array($my_Arr[$k][$l+1],$my_Arr[$i])) {
array_push($my_Arr[$i], $my_Arr[$k][$l+1]);
}
}
}
}
}
}
}
}
echo "<pre>";
print_r($my_Arr);