I've got a mind bender here.
I have X number of books, each of which is available at X number of stores. I have to come up with all the possible combinations.
The script is self-reflexive. The problem is that once a variable is called within a function, it appears to live on with it's previous value the next time the function is called.
My script should output
ACF
ACG
ADF
ADG
AEF
AEG
BCF
BCG
BDF
BDG
BEF
BEG
Instead it outputs
ACF
ACFGDE
here's the script. This is actually pretty fun. I suggest you copy and paste it and try it out. It's sure to make your head swim.
Anyway, TIA
Jeff
<?
$ISBNstores['11111111'] = array('A','B');
$ISBNstores['22222222'] = array('C','D','E');
$ISBNstores['33333333'] = array('F','G');
$first = key($ISBNstores);
combos($first,'');
function combos($isbn,$currentCombo){
global $ISBNstores, $first;
while(list($key,$val)=each($ISBNstores[$isbn])){
$currentCombo .= "$val";
echo "<LI>current combo now $currentCombo";
next($ISBNstores);
$nextISBN = key($ISBNstores);
if($nextISBN){
echo "<LI>next isbn is $nextISBN";
combos($nextISBN,$currentCombo);
} else {
echo "<LI>$currentCombo";
//reset($ISBNstores[$isbn]);
reset($ISBNstores);
/ This will echo "AAA" or "AAB", etc.
It's the place where you figure out the final price for this combination.
/
}
//prev($ISBNstores);
//echo "<LI>key to isbnstores is now ".key($ISBNstores);
//if(key($ISBNstores) != $first) reset($ISBNstores[$isbn]);
}
}
?>