note 26821 added to control-structures.switch

From: Date: Thu, 14 Nov 2002 01:55:34 +0000
Subject: note 26821 added to control-structures.switch
Groups: php.notes 
Request: Send a blank email to php-notes+get-39466@lists.php.net to get a copy of this message
this is a simple function that returns a random string and uses switch to determine what kind of string you want. function r( [string prefix][,int type,][,int chars] ); type = 1 -> only numbers type = 2 -> only letters type = 3 -> both function r($prefixo = "",$tipo = 3,$numcaracteres = 10) { switch ($tipo) { case 1: for ($x = 1; $x <= $numcaracteres; $x++) { $rnum .= chr(rand(48,57)); } return $prefixo . $rnum; break; case 2: for ($x = 1; $x <= $numcaracteres; $x++) { if (rand(1,2) == 1) { $rletras .= chr(rand(65,90)); } else { $rletras .= chr(rand(97,122)); } } return $prefixo . $rletras; break; case 3: for ($x = 1; $x <= $numcaracteres; $x++) { $r = rand(1,3); if ($r == 1) { $rstring .= chr(rand(65,90)); } elseif ($r == 2) { $rstring .= chr(rand(97,122)); } else { $rstring .= chr(rand(48,57)); } } return $prefixo . $rstring; break; } } -- http://www.php.net/manual/en/control-structures.switch.php http://master.php.net/manage/user-notes.php?action=edit+26821 http://master.php.net/manage/user-notes.php?action=delete+26821 http://master.php.net/manage/user-notes.php?action=reject+26821

« previous php.notes (#39466) next »