$files = ['a','b','c','d','e','f'];
$other = ['a','b','c','d','e','f'];
foreach($files as $k => $file){
foreach($other as $key => $value){
$data = [
'column1' => $file,
'column2' => $value,
];
if($file == $value){
return false
}else{
DB::table('abed')->insert($data);
}
}
}
How to make combination of two array without duplicate records and cross duplicate remove
DB insert like that
|column1 | column2 |
|------- | ------- |
| a | b |
| a | c |
| a | d |
| a | e |
| a | f |
| b | a |
| b | c |
| b | d |
| b | e |
| b | f |
| c | a |
| c | b |
| c | d |
| c | e |
| c | f |
| d | a |
| d | b |
| d | c |
| d | e |
| d | f |
| e | a |
| e | b |
| e | c |
| e | d |
| e | f |
| f | a |
| f | b |
| f | c |
| f | d |
| f | e |
I want like this DB insert
| a | b |
| a | c |
| a | d |
| a | e |
| a | f |
| b | c |
| b | d |
| b | e |
| b | f |
| c | d |
| c | e |
| c | f |
| d | e |
| d | f |
| e | f |
3
Answers
You used
in_array()
, refer to the below code :For this another example
| a | b |
| a | c | | a | d | | a | e | | a | f | | b | c | | b | d | | b | e | | b | f |
For another example ,
@Vaibhav try this,
Hope this will helpful for you.
Also I change in execute query only once instead of execute in loop.