Ver Mensaje Individual
  #16 (permalink)  
Antiguo 07/08/2011, 14:49
Avatar de andresdzphp
andresdzphp
Colaborador
 
Fecha de Ingreso: julio-2011
Ubicación: $this->Colombia;
Mensajes: 2.749
Antigüedad: 12 años, 9 meses
Puntos: 793
Respuesta: metodo burbuja en el lenguaje de programacion PHP

aquí está la forma que te decía @abimaelrc

Código PHP:
Ver original
  1. <?php
  2.  
  3. function ordenar($arr) {
  4.     $count = count($arr);
  5.     for ($i = 1; $i < $count; $i++) {
  6.         $tmp = $arr[$i];
  7.         for ($j = $i - 1; $j >= 0 && $arr[$j] > $tmp; $j--)
  8.             $arr[$j + 1] = $arr[$j];
  9.         $arr[$j + 1] = $tmp;
  10.     }
  11.     return $arr;
  12. }
  13.  
  14. $a = array(2, 35, 22, 20, 15);
  15.  
  16. foreach (ordenar($a) as $o) {
  17.     echo $o . '<br />';
  18. }
__________________
Si sabemos como leer e interpretar el manual será mucho más fácil aprender PHP. En lugar de confiar en ejemplos o copiar y pegar - PHP

Última edición por andresdzphp; 07/08/2011 a las 14:54