Created
December 13, 2020 01:57
-
-
Save jorgecc/1567ac2ae8abff260798b665182e47e9 to your computer and use it in GitHub Desktop.
example.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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