Jump to content

I am a Biginner and Needs Help.


vandutch

Recommended Posts

I have tried to browse the internet for a solution related to this problem. But I haven't found one.

 

How do I solve this problem?

 

If I input "A B C and so on..." the output will be the following:

A

B

C

A B

A C

B A

B C

C A

C B

A B C

A C B

B A C

B C A

C A B

C B A

an so on....

Link to comment
https://forums.phpfreaks.com/topic/189131-i-am-a-biginner-and-needs-help/
Share on other sites

I'm trying to make a script that creates possible word combinations...

example: I'll input the following words "she, my, mother, is, really, beautiful,".

the possible outcome can be: "my mother is really beautiful, mother is beautiful, is beautiful, she is beautiful, etc.".

 

 

you need to be able to find some logical process that will change the word order to suit your needs. The ABC example and output you pasted seems to be doing what i'd imagine it is meant to do. Output all possible variations of the letter positions in string 'ABC'.

 

It is going to be rather difficult to get the computer to determine combinations of words that are still grammatically correct like your example two posts above, since the meanings of the words mean nothing to the computer! They're just 0s and 1s to the computer.

Oh! I forgot to mention that grammar doesn't matter. All that matters are the combination.

To clear everything out I will change my example into:

 

I'll input the following words "she, my, mother, is, really, beautiful,".

 

the output will be:

 

she

my

mother

is

really

beautiful

she my

she mother

she is

she really

she beautiful

my she

my mother

my is

my really

my beautiful

mother she

mother my

mother is

mother really

mother beautiful

is she

is my

is mother

is really

is beautiful

my mother is really beautiful

mother is beautiful

is beautiful

she is beautiful

etc.

 

I am having hard time to figure out a logical way to create a combination as I only know basic PHP.

as close as i can get so far.

 

<?php

$array=array("my" , "mother" , "is" , "really" , "beautiful");

for($i=0; $i<count($array); $i++){

shuffle($array);

$a=$array[0].' '.$array[1].' '.$array[2].' '.$array[3].' '.$array[4];

echo "$a <br>";

}

?>

my way and it fall proof, it also compare the result, are correct not duplicated.

 

This code, will only produce the number of results, via the count of the array.

 

<?php

$array=array("my" , "mother" , "is" , "really" , "beautiful");

for($i=0; $i<count($array); $i++){

shuffle($array);

$a[]=$array[0].' '.$array[1].' '.$array[2].' '.$array[3].' '.$array[4];

$b=array_unique($a);

}

foreach($b as $res){

echo" $res <br> ";

}

?>

Thank you fro your reply redarrow. The code u used is slightly different from mine, however the output is still the same which I stated at reply #3.. Check out reply #3, I showed all possible combination but it was not what I want it.

 

In reply #5 is the output I want to get.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.