vandutch Posted January 20, 2010 Share Posted January 20, 2010 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 More sharing options...
pneudralics Posted January 20, 2010 Share Posted January 20, 2010 What are you trying to do? Link to comment https://forums.phpfreaks.com/topic/189131-i-am-a-biginner-and-needs-help/#findComment-998501 Share on other sites More sharing options...
vandutch Posted January 20, 2010 Author Share Posted January 20, 2010 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.". Link to comment https://forums.phpfreaks.com/topic/189131-i-am-a-biginner-and-needs-help/#findComment-998510 Share on other sites More sharing options...
vandutch Posted January 20, 2010 Author Share Posted January 20, 2010 I tried to create an array for A B C and tried to shuffle it.. but the output is: A B C A C B B A C B C A C A B C B A The output is not the same as what I wanted it to be. Please help me.. Link to comment https://forums.phpfreaks.com/topic/189131-i-am-a-biginner-and-needs-help/#findComment-998529 Share on other sites More sharing options...
Catfish Posted January 20, 2010 Share Posted January 20, 2010 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. Link to comment https://forums.phpfreaks.com/topic/189131-i-am-a-biginner-and-needs-help/#findComment-998537 Share on other sites More sharing options...
vandutch Posted January 20, 2010 Author Share Posted January 20, 2010 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. Link to comment https://forums.phpfreaks.com/topic/189131-i-am-a-biginner-and-needs-help/#findComment-998542 Share on other sites More sharing options...
redarrow Posted January 20, 2010 Share Posted January 20, 2010 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>"; } ?> Link to comment https://forums.phpfreaks.com/topic/189131-i-am-a-biginner-and-needs-help/#findComment-998545 Share on other sites More sharing options...
redarrow Posted January 20, 2010 Share Posted January 20, 2010 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> "; } ?> Link to comment https://forums.phpfreaks.com/topic/189131-i-am-a-biginner-and-needs-help/#findComment-998547 Share on other sites More sharing options...
vandutch Posted January 20, 2010 Author Share Posted January 20, 2010 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. Link to comment https://forums.phpfreaks.com/topic/189131-i-am-a-biginner-and-needs-help/#findComment-998568 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.