Tema: Suma While
Ver Mensaje Individual
  #3 (permalink)  
Antiguo 04/03/2012, 03:36
Avatar de repara2
repara2
 
Fecha de Ingreso: septiembre-2010
Ubicación: München
Mensajes: 2.445
Antigüedad: 13 años, 7 meses
Puntos: 331
Respuesta: Suma While

Código PHP:
Ver original
  1. <?php
  2. ini_set("display_errors", 1);
  3. $ids = array(1,2,3,2,3,4,5,4,3,4,5,6,7,6,7,8,9,8,9,8,7,6,5,4);
  4.  
  5. $resultados = array();
  6. for($i = 0; $i<count($ids); $i++)
  7. {
  8.     if(!array_key_exists($ids[$i], $resultados)) $resultados[$ids[$i]] = 1;
  9.     else $resultados[$ids[$i]]++;
  10. }
  11.  
  12. echo "<pre>";
  13. echo "<h3>Origen:</h3>";
  14. print_r($ids);
  15. echo "<h3>Recuento:</h3>";
  16. print_r($resultados);
  17. echo "</pre>";
  18. ?>
__________________
Fere libenter homines, id quod volunt, credunt.