lundi 26 février 2018

delete repeated elements array php

I have this code in my controller

foreach ($xml->xpath('//cfdi:Comprobante//cfdi:Impuestos//cfdi:Traslados//cfdi:Traslado') as $col){

    if($col['impuesto']=='IVA'){                                                                                                                                                        
        $total_traslados['IVA']=0;
    }
    if($col['impuesto']=='IEPS'){
        $total_iva  =   $total_iva + $col['importe'];
        $total_traslados['IEPS']=$total_iva;
    }
    if($col['impuesto']=='ISR'){
        $total_iva  =   $total_iva + $col['importe'];
        $total_traslados['ISR']=0;
    }
    echo "<br>";
    print_r($total_traslados);
    echo "<br>";
}  

And this is the result of the array

Array ( [IVA] => 0 )

Array ( [IVA] => 0 )

Array ( [IVA] => 0 )

Array ( [IVA] => 0 [IEPS] => 123 )

Array ( [IVA] => 0 [IEPS] => 123 [ISR] => 0 )

Array ( [IVA] => 0 [IEPS] => 123 [ISR] => 0 )

Array ( [IVA] => 0 [IEPS] => 123 [ISR] => 0 )

Array ( [IVA] => 0 [IEPS] => 123 [ISR] => 0 )

Array ( [IVA] => 0 [IEPS] => 123 [ISR] => 0 )

Array ( [IVA] => 0 [IEPS] => 1111111 [ISR] => 0 )

Array ( [IVA] => 0 [IEPS] => 1111111 [ISR] => 0 )

Array ( [IVA] => 0 [IEPS] => 1111111 [ISR] => 0 )

Array ( [IVA] => 0 [IEPS] => 1111111 [ISR] => 0 )

Array ( [IVA] => 0 [IEPS] => 1111111 [ISR] => 0 )

Array ( [IVA] => 0 [IEPS] => 1111111 [ISR] => 0 )

Array ( [IVA] => 0 [IEPS] => 1111111 [ISR] => 0 )

Array ( [IVA] => 0 [IEPS] => 7920 [ISR] => 0 )

Array ( [IVA] => 0 [IEPS] => 7920 [ISR] => 0 )

Array ( [IVA] => 0 [IEPS] => 14174 [ISR] => 0 )

How can i delete repeated elements?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire