Ver Mensaje Individual
  #4 (permalink)  
Antiguo 10/07/2011, 07:15
oms02
 
Fecha de Ingreso: junio-2010
Mensajes: 373
Antigüedad: 13 años, 10 meses
Puntos: 11
Respuesta: rotar valores de un array

Lo acabo de hacer pero he utilizado muchas variables, creo.

Hay alguna manera de reducir un poco el numero de variables??

Código PHP:
Ver original
  1. //$tipo es la variable que pide el usuario, la que contiene uno de los valores del array $tit.
  2.  
  3. $tit = array('nmb','dir','tel','eda');
  4.  
  5. $j=0;
  6. while($tit[$j]!=$tipo)
  7.     {$j++;}
  8.  
  9. $ntit=array(4);
  10. $n=0;
  11. if($j>0)
  12.     {
  13.     for($i=3;$i>=0;$i--)
  14.         {
  15.         $k=$i-$j;
  16.         if($k<0)
  17.             {
  18.             $m=3-$n;
  19.             $ntit[$m]=$tit[$i];
  20.             $n++;
  21.             }
  22.         else
  23.             {$ntit[$k]=$tit[$i];}
  24.         }
  25.     }
  26. else
  27.     {$ntit=$tit;}