$example1 = array(3, 9, 5, 12);
$example2 = array(5, 4);
$example3 = array(8, 2, 4, 7, 3);
How can I get combination one to one between these array elements without repetition?
For $example1
should return:
3 9
3 5
3 12
9 5
9 12
5 12
$example2:
5 4
$example3:
8 2
8 4
8 7
8 3
2 4
2 7
2 3
4 7
4 3
7 3
I tried:
<?php
$example3 = array(8, 2, 4, 7, 3);
foreach ($example3 as $e) {
foreach ($example3 as $e2) {
if ($e != $e2) {
echo $e . ' ' . $e2 . "\n";
}
}
}
This return me: http://codepad.org/oHQTSy36
But how is the best way to exclude repetition?