catcalls
Senior Developer
Joined: 12 Aug 2005
Posts: 161
51 Cash
|
This script takes any number within reason and fills an array with each number value. In the script we use 14 different numbers ranging from 1 to 14. But this can be changed.
The next step is to produce every combination without redundancy and fill another array with the combinations of the first array. This is where is gets tricky, because what happens here is that the combinations are dependent on the order of the first array. This is actually how it is supposed to work.
Finally we output all the combinations to screen just to check that the script is working.
You may wonder why I needed this script - but here is a real life example;
I have 14 glamour models each with their own name. I use a <SELECT MULTIPLE> option in a HTML form where the user can select any combination of models to look at...The models are listed in a specific order in the SELECT tag so the order does not change, only the possible combinations. Hence the need for the script to be dependent on the order of the input values.
There cannot be any redundancy, and there is not! For example, since the user can only select model 1 once, there is no use for model 1 to be listed twice in one combination such as 112. Therefore there is no redundacy in that matter.
I used the output to fill a database with all combinations (over 200 for 14 models) so I can have a list of combinations to create statistics with and had a model List ID attached to each model combination.
I soon thought about other ways I could use such a program, but one program I am working on at the moment is to expand the combinations to include all possible variations of the SELECT model list. That part is pretty tricky as it took me two days and 1 failed attempt to actually code this script to produce the exact output needed. I feel I could replace the counters with more loops but then it may get confusing...
catcalls
robbiedave.com
|