Skip to content

Instantly share code, notes, and snippets.

@jorgecc
Created December 13, 2020 01:57
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jorgecc/1567ac2ae8abff260798b665182e47e9 to your computer and use it in GitHub Desktop.
example.php
<?php
$data=[[101, "ABC", "MX993767772", "04/12/2000", 1, "J176", 1],
[101, "ABC", "MX993767772", "04/12/2000", 1, "J108", 2],
[127918, "RMT", "MX993767772", "04/12/2000", 1, "J108", 2]];
$result=[];
foreach($data as $k=>$v) {
// find value
$found=false;
foreach($result as $k2=>$v2) {
if($v[0]===$v2[0] && $v[1]===$v2[1] && $v[2]===$v2[2] && $v[3]===$v2[3] && $v[4]===$v2[4]) {
// found it so updating
$result[$k2][5].=','.$v[5];
$result[$k2][6].=','.$v[6];
$found=true;
break;
}
}
if(!$found) {
// adding
$result[]=$v;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment