Location: PHPKode > scripts > Permutation Lower Upper > permutation-lower-upper/PermutationLowerUpper.php
<?
/**
 * PermutationLowerUpper - Version 0.1
 * 2005-12-06
 *
 * PermutationLowerUpper use to : 
 *  input: 		"ab" 
 *  outpuo: 	array("ab","Ab","aB","AB")
 *
 * Created by Arcangelo Casavola 
 * hide@address.com
 */


class perm_uplow{
	var $str="";
	var $len_str=0;
	var $out_ar=array();
	var $out_str=array();

	function perm_uplow($str){
		$this->str=$str;
		$this->len_str=strlen($str);
	}

	function get_perm_uplow(){
		$len=strlen($this->str);
		$this->create_perm($this->str,"");
		$this->creat_array_p($this->out_ar);
	}

	function create_perm($str,$val=""){
		if ($str!=""){
			$this->out_ar[]=array($val.strtolower($str{0}),$this->create_perm(substr($str,1,strlen($str)),$val.strtolower($str{0})) );
			$this->out_ar[]=array($val.strtoupper($str{0}),$this->create_perm(substr($str,1,strlen($str)),$val.strtoupper($str{0})) );
		}
	}

	function creat_array_p($a=array()){
		while (list($key, $value) = each ($a)) {
		if(count($value)<1) continue;
		   if((gettype($value)=="array") && (count($value)>0)) $this->creat_array_p($value);
		   elseif($this->len_str==strlen($value)) $this->out_str[]=$value;
		}
	}

	function get_out_str(){
		return $this->out_str;
	}
	function get_out_ar(){
		return $this->out_ar;
	}
	function get_len_str(){
		return $this->len_str;
	}

}

//example of use
$t=microtime();
$a = new perm_uplow("asd");
$a->get_perm_uplow();
print_r($a->get_out_str());
echo $t-microtime();

?>
Return current item: Permutation Lower Upper