Jump to content

Help need


mediatomcat

Recommended Posts

I have an array: $myarray  = explode(',','a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,1,2,3,4,5,6,7,8,9,0');

 

I am try to generate a sequence of strings starting with:

 

a and then going to b and to c, etc until I hit 0.  Then I want the string to become:

aa and to become ab and to ac, etc until I hit a0. Then I want the string to become:

ba , etc until I 36 character string all at zero's. 

 

Basically I would like to give a value to a fucntion like a and it delivers the next in sequence.  I have been trying for hours but cannot do it, can anyone help?

Link to comment
https://forums.phpfreaks.com/topic/203261-help-need/
Share on other sites

$array = array_merge(range('A', 'Z'), range(1, 9), array(0));
$recur = new MyRecur();
$recur->perform($array);
print_r($recur->getArray());

 

class MyRecur {
  private $array = array();
  
  public function perform($array, $prefix = '') {
    foreach ($array as $value) {
      $this->array[] = $prefix . $value;
      $this->perform($array, $prefix . $value);
    }
  }
  
  public function getArray() {
    return $this->array;
  }
}

 

PS: I hope you have LOOOTTTTSSSSS of RAM because the output of this array equals: 3.7x10^41

Link to comment
https://forums.phpfreaks.com/topic/203261-help-need/#findComment-1064962
Share on other sites

Maybe if I show you how far I got:

 

function createPointer($val) {
	$ary  = explode(',','a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,1,2,3,4,5,6,7,8,9,0');
	$fullstring = $val;
	$pointer = substr($fullstring, -1);
	$key = array_search($pointer, $ary);
	if ($ary[$key+1] == "") {
		$nextval = $ary[0];
	} else {
		$nextval = $ary[$key+1];
	}
	if ($ary[$key+1] == "") {
		echo "Do Switch - Previous ";
		echo "Val: ".$val;
		echo "<br>String Length: ".strlen($val);

	} else {
		// for std string
		$fullstring = substr($fullstring, 0, -1);
		echo "2 (New Val) - ".$fullstring.$nextval;
	}
}

Link to comment
https://forums.phpfreaks.com/topic/203261-help-need/#findComment-1064970
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.