Forum Moderators: coopster

Message Too Old, No Replies

Bad function

doesn't count

         

WhosAWhata

4:45 am on Apr 6, 2005 (gmt 0)

10+ Year Member



i have this code

$a = array("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", "-");
$r = count($a)-1;
$t = array(0,0,0,0,0,0,0,0,0,0,0,0);
function nextcode(){
global $t;
$t['11']++;
if($t['11'] > $r) { $t['11']=0; $t['10']++; }
if($t[10] > $r) { $t[10]=0; $t[9]++; }
if($t[9] > $r) { $t[9]=0; $t[8]++; }
if($t[8] > $r) { $t[8]=0; $t[7]++; }
if($t[7] > $r) { $t[7]=0; $t[6]++; }
if($t[6] > $r) { $t[6]=0; $t[5]++; }
if($t[5] > $r) { $t[5]=0; $t[4]++; }
if($t[4] > $r) { $t[4]=0; $t[3]++; }
if($t[3] > $r) { $t[3]=0; $t[2]++; }
if($t[2] > $r) { $t[2]=0; $t[1]++; }
if($t[1] > $r) { $t[1]=0; $t[0]++; }
return $a[$t[0]] . $a[$t[1]] . $a[$t[2]] . $a[$t[3]] . $a[$t[4]] . $a[$t[5]] . $a[$t[6]] . $a[$t[7]] . $a[$t[8]] . $a[$t[9]] . $a[$t[10]] . $a[$t[11]];
}

every time i call it, it is supposed to return the next 12 digit "code" in sequence

ex:
first
AAAAAAAAAAAB

second:
AAAAAAAAAAAC

"$r+1" th:
AAAAAAAAAABA

"$r+2" th:
AAAAAAAAAABB

THANKS FOR YOUR HELP

WhosAWhata

11:41 pm on Apr 6, 2005 (gmt 0)

10+ Year Member



I've tried writting it like
$t[11] and $t['11']

the 'quotes' don't seem to make a difference

and a print_r after it shows that $t['11'] always equals 1 which means that it is being added to, but then forgotten, thats why i added the "global $t" but it didn't change anything.

any ideas?

ironik

12:06 am on Apr 7, 2005 (gmt 0)

10+ Year Member



It might be a problem with the loop you are using to call the function, can you post that code as well?

The quotes for a numbered key in an array don't matter, but if you are using a string then you'll have to use them.

WhosAWhata

4:49 pm on Apr 9, 2005 (gmt 0)

10+ Year Member



i got it all figured out. i had fixed the code to what i posted, but the browser had an older section cached