This is trying to put the records in a new array, but without putting duplicate records. I have an array with duplicate RFCs and I am discarding those that are duplicates, for that I am using the PHP in_array function, I already discard the duplicate RCFs and put them in the array $test all the RFCs, but without duplicating them, only now I need to put them too your account_name.
I hope you can support me.
Code
<?php
$array_cuentas = array(
Array (
"troncal" => "2875",
"RFC" => "CAR080630JF6",
"nombre_cuenta" => "Chacon & Rodriguez Asociados",
"DIDS" => Array (
525512090447),
"id_cdr" => "2875"
),
Array (
"troncal" => "2777",
"RFC" => "ADA000803GM5",
"nombre_cuenta" => "Almacenaje y Distribucion Avior SA de CV",
"DIDS" => Array (
525546249183),
"id_cdr" => "2773"
),
Array (
"troncal" => "2876",
"RFC" => "TLE011122SC2",
"nombre_cuenta" => "Tralix Mexico S de RL de CV",
"DIDS" => Array (
525512090445,
525526230587,
525552024342,
525552024546),
"id_cdr" => "2893"
),
Array (
"troncal" => "2893",
"RFC" => "TLE011122SC2",
"nombre_cuenta" => "Tralix Mexico S de RL de CV",
"DIDS" => Array (
524421611002,
525512090438,
525512090439,
525552024483),
"id_cdr" => "2893"
));
unificarTroncales($array_cuentas);
function unificarTroncales($array_cuentas){
$pruebita = array();
foreach ($array_cuentas as $key => $value) {
if(!in_array($value["RFC"], $pruebita)){
//Si el RFC no existe en el array $pruebita lo meto en el array, pero neecsito tambien meter el nombre_cuenta
$pruebita[] = $value['RFC'];
}
}
//Imprimo para comprovar que no se dupliquen
print_r($pruebita);
}
?>
To make things easier and avoid loops within loops, simply create two variables: One to store just the RFCs and do the validation, and one to store all the data you need:
Have you tried using array_push() ?
or if you want it that way
also with all the data