Forum Moderators: coopster

Message Too Old, No Replies

Arrange

A set of numbers...

         

inveni0

5:24 pm on Apr 24, 2006 (gmt 0)

10+ Year Member



If I have 3 single digit numbers, is there a way to have PHP echo all possible combinations (orders) of the numbers?

alce

5:42 pm on Apr 24, 2006 (gmt 0)

10+ Year Member



You could write a script to display all possible permutations but I believe you would be better off using Mysql tables. Create 3 tables with the digits 0-9 and then perform a cross query.

SELECT table1.*, table2.*, table3.* FROM table1 , table2, table3

I believe this query will return all possible permutations

inveni0

5:49 pm on Apr 24, 2006 (gmt 0)

10+ Year Member



Well, they could be letters, too. I basically want to input the characters and have them instantly arranged in every possible order, without reusing the same character more than once.

alce

6:56 pm on Apr 24, 2006 (gmt 0)

10+ Year Member



Ok, so if you have only 3 charcters (or numbers) and you do not want to use them more than once you have only 6 possible combinations. Is that what you want to achieve?

Say you have a, b, c. The possible outcomes would then be:

abc
acb
bca
bac
cba
cab

is that correct?

inveni0

7:03 pm on Apr 24, 2006 (gmt 0)

10+ Year Member



That's correct, but I'm simplifying my planned script. I will in reality have 6 characters from which I want all possible combinations of for sets of 3-6 characters...

...I just thought if there was a built in method to this, I may be able to apply it to the whole set.

I suppose I could insert the digits into a table and then pull out 3 randomly and sort them randomly like 100 times.