mediatomcat Posted May 29, 2010 Share Posted May 29, 2010 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 More sharing options...
ignace Posted May 29, 2010 Share Posted May 29, 2010 $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 More sharing options...
mediatomcat Posted May 29, 2010 Author Share Posted May 29, 2010 Lol. I am not generating the entire string in one sitting. Ill give it a try, thanks... Link to comment https://forums.phpfreaks.com/topic/203261-help-need/#findComment-1064966 Share on other sites More sharing options...
mediatomcat Posted May 29, 2010 Author Share Posted May 29, 2010 I see what you mean about the RAM. Gulp. Can it be done where you call a function with a value like: $currentval = "ab" createNextVal($currentval); then a function returns ac, etc. Link to comment https://forums.phpfreaks.com/topic/203261-help-need/#findComment-1064968 Share on other sites More sharing options...
mediatomcat Posted May 29, 2010 Author Share Posted May 29, 2010 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 More sharing options...
mediatomcat Posted May 29, 2010 Author Share Posted May 29, 2010 Any ideas? Its doing my head in. Link to comment https://forums.phpfreaks.com/topic/203261-help-need/#findComment-1064979 Share on other sites More sharing options...
mediatomcat Posted May 29, 2010 Author Share Posted May 29, 2010 Its alright, founda different way to do it... Link to comment https://forums.phpfreaks.com/topic/203261-help-need/#findComment-1065019 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.