domingo, 10 de noviembre de 2013

Función en php para el uso de flags, 1 2 4 8 16 32 64 128 256

Ésta función devuelve las banderas activas en un Array con su valor.

  1. function flagsUser($SS) {
  2.         //if($SS - 2048 >= 0) { $r[2048] = true; $SS -= 2048; } //Opcion 10
  3.         if($SS - 2048 >= 0) { $r[2048] = true; $SS -= 2048; } //Opcion 9
  4.         if($SS - 1024 >= 0) { $r[1024] = true; $SS -= 1024; } //Opcion 8
  5.         if($SS -  512 >= 0) { $r[ 512] = true; $SS -=  512; } //Opcion 7
  6.         if($SS -  256 >= 0) { $r[ 256] = true; $SS -=  256; } //Opcion 6
  7.         if($SS -  128 >= 0) { $r[ 128] = true; $SS -=  128; } //Opcion 5
  8.         if($SS -   64 >= 0) { $r[  64] = true; $SS -=   64; } //Opcion 4
  9.         if($SS -   32 >= 0) { $r[  32] = true; $SS -=   32; } //Opcion 3
  10.         if($SS -   16 >= 0) { $r[  16] = true; $SS -=   16; } //Opcion 2
  11.         if($SS -    8 >= 0) { $r[   8] = true; $SS -=    8; //Opcion 1
  12.         if($SS -    4 >= 0) { $r[   4] = true; $SS -=    4; } //ADMINISTRADOR
  13.         if($SS -    2 >= 0) { $r[   2] = true; $SS -=    2; } //MODERADOR
  14.         if($SS -    1 >= 0) { $r[   1] = true; $SS -=    1; } //USUARIO
  15.     return $r;        
  16. }