Ver Mensaje Individual
  #2 (permalink)  
Antiguo 24/04/2009, 13:13
Avatar de Ronruby
Ronruby
 
Fecha de Ingreso: julio-2008
Ubicación: 18°30'N, 69°59'W
Mensajes: 4.879
Antigüedad: 16 años, 8 meses
Puntos: 416
Respuesta: ayuda 2arrays combinar Urgente!!!

Código php:
Ver original
  1. <?php
  2.  
  3. $array = array("gato", "perro", "perro", "perico", "perro");
  4. $nums = array(1, 2, 2, 5, 8);
  5.  
  6. $result = array();
  7.  
  8. for($i = 0; $i < count($array); $i++) {
  9.     if(isset($result[$array[$i]])) {
  10.         $result[$array[$i]] += $nums[$i];
  11.     } else {
  12.         $result[$array[$i]] = $nums[$i];
  13.     }
  14. }
  15.  
  16. print_r($result);
  17.  
  18. ?>

Última edición por Ronruby; 24/04/2009 a las 13:39