I'm trying to simply match these letters using php, but it's kind-of a complex matching formula...

First, I have two arrays and one string. The arrays contain letters and the string is a near match of those letters.

\$a - [Array] Must be <= 7
\$b - [Array] Must be >= 0
\$word - [String] Must contain letters from \$a & \$b. Letters can't be used twice.

The Goal: Create a word from those letters with complex matching. To start each word must contain one and only one \$b letter, unless no \$b letters are given. Next it must make sure that \$word only contains letters from \$a (it can't use letters twice but \$a can contain the same letter) (and of course one or zero \$b letters).

Example #1:
\$a = R-E-O-E
\$b = E-P
\$word = Red
(The code should look at this an not accept it because \$a nor \$b doesn't contain a D)

Example #2:
\$a = R-E-O-E
\$b = E-P
\$word = Peer
(The code should accept this because \$b contains P and \$a contains two E's and an R)

Note: This will be in a long loop with many different words.

Any help will be greatly appreciated!

## All 22 Replies

Try this:

``````<?php

\$a = array('test','text','ext','tex','deer'); # words to filter
\$b = array('e','s','t','d','r'); # letters to check

function c(\$letter,\$array)
{
\$n = strlen(\$letter);
\$r = array();
for(\$i = 0; \$i < \$n; \$i++)
{
if(in_array(\$letter[\$i],\$array))
{
\$r[] = true;
}
else
{
\$r[] = false;
}
}
return (in_array(null,\$r)) ? false:true;
}

foreach(\$a as \$word)
{
echo \$word .': '. c(\$word,\$b) . "\n";
}
?>``````

bye.

Try this:

``````<?php

\$a = array('test','text','ext','tex','deer'); # words to filter
\$b = array('e','s','t','d','r'); # letters to check

function c(\$letter,\$array)
{
\$n = strlen(\$letter);
\$r = array();
for(\$i = 0; \$i < \$n; \$i++)
{
if(in_array(\$letter[\$i],\$array))
{
\$r[] = true;
}
else
{
\$r[] = false;
}
}
return (in_array(null,\$r)) ? false:true;
}

foreach(\$a as \$word)
{
echo \$word .': '. c(\$word,\$b) . "\n";
}
?>``````

bye.

Great suggestion, but that isn't really what I'm looking for. If you look back at my example I explain two different arrays and one word.

Thanks for trying!

I'm sorry, now it should work like you want:

``````<?php
\$a = array('e','x','t','d','a');
\$b = array('r','g','n');
\$word = 'extra'; # try "gextra" for example, because of g and r it will give false

function c(\$word,\$array,\$barray)
{
\$n = strlen(\$word);
\$r = array();
\$bn = 0;
for(\$i = 0; \$i < \$n; \$i++)
{
if(in_array(\$word[\$i],\$array))
{
\$r[\$i] = true;
}
else
{
\$r[\$i] = false;
}

if(in_array(\$word[\$i],\$barray))
{
if(\$bn == 0)
{
\$bn = 1;
\$r[\$i] = true;
}
else
{
\$r[\$i] = false;
}
}
}

return (in_array(null,\$r)) ? false:true;
}

echo \$word .': '. c(\$word,\$a,\$b) . "\n";
echo "\n";
?>``````

bye :)

I'm sorry, now it should work like you want:

``````<?php
\$a = array('e','x','t','d','a');
\$b = array('r','g','n');
\$word = 'extra'; # try "gextra" for example, because of g and r it will give false

function c(\$word,\$array,\$barray)
{
\$n = strlen(\$word);
\$r = array();
\$bn = 0;
for(\$i = 0; \$i < \$n; \$i++)
{
if(in_array(\$word[\$i],\$array))
{
\$r[\$i] = true;
}
else
{
\$r[\$i] = false;
}

if(in_array(\$word[\$i],\$barray))
{
if(\$bn == 0)
{
\$bn = 1;
\$r[\$i] = true;
}
else
{
\$r[\$i] = false;
}
}
}

return (in_array(null,\$r)) ? false:true;
}

echo \$word .': '. c(\$word,\$a,\$b) . "\n";
echo "\n";
?>``````

bye :)

You're smart, but not quite there yet! For example, I tried the word "exta" which contains no letters from the \$b array. Each word must contain letters from the \$b array unless no letters are in the \$b array.

Another problem is if I do the word "exxtra" it contains two x's, but the \$a array only contains one x.

Thanks!

Try it and let me know, I've tried to match your examples..

``````<?php

# count and compare values between array a and word
function d(\$word, \$array)
{
global \$d;
\$u = array_unique(\$array);
\$w = str_split(\$word);

\$u2 = array_intersect(\$u,\$w);
\$a1 = array_count_values(\$array);
\$w1 = array_count_values(\$w);
\$a = array();
foreach(\$u2 as \$k => \$v)
{
\$a[] = (\$a1[\$v] >= \$w1[\$v]) ? true:false;
}

\$d = in_array(false,\$a) ? false:true;
return \$d;
}

# check array b
function e(\$word,\$barray)
{
global \$e;
\$r = array();
\$n = str_split(\$word);
\$bn = 0;
if(count(\$barray) != 0 && is_array(\$barray))
{
for(\$i = 0; \$i < count(\$n); \$i++)
{
if(in_array(\$n[\$i],\$barray))
{
if(\$bn == 0)
{
\$bn++;
\$r[] = 1;
}
else
{
\$bn++;
\$r[] = 2;
}
}
else
{
\$r[] = 3;
}
}
}
elseif(count(\$barray) == 0 && is_array(\$barray))
{
\$r[] = 1;
}
else
{
\$r[] = 0;
}

# codes:
# 0 no array
# 1 array yes, letter matched or empty array
# 2 array yes, more than one letter matched
# 3 array yes, no letter

\$e = (in_array(1,\$r) == true && in_array(2,\$r) == false) ? true:false;
return \$e;
}

# check array a
function c(\$word,\$array)
{
global \$d;
global \$e;
\$n = str_split(\$word);
\$r = array();
for(\$i = 0; \$i < count(\$n); \$i++)
{
if(in_array(\$n[\$i],\$array))
{
\$r[] = true;
}
elseif(\$e == true)
{
\$r[] = true;
}
else
{
\$r[] = false;
}
}

\$res = array();
\$res[] = \$d;
\$res[] = \$e;
\$res[] = in_array(false,\$r) ? false:true;
return in_array(false,\$res) ? 'false':'true';
}

\$a = array('x','x','e','t','d','a');
\$b = array('r','g','n');
#\$b = array(); # empty array
\$word = 'exxxta';

d(\$word,\$a);
e(\$word,\$b);
print_r(c(\$word,\$a));
?>``````

hope I got it this time.. :D

Thanks Ceral, I'm not quite sure if that worked. Here is all of my code. Calm down. I know it's messy...

``````<?php

if(empty(\$_POST['yl']))
{
echo "<form action='index.php' method='POST'>Your Letters: <input type='text' name='yl'>Board Letters: <input type='text' name='bl'><input type='submit'></form>";
}
else
{

\$a = preg_split('//', \$_POST['yl']);
\$b = preg_split('//', \$_POST['bl']);

function pc_permute(\$items, \$perms = array( )) {
if (empty(\$items)) {

\$workWords = array();

\$a = array('g','p');
\$b = array('o');

\$w = join('', \$perms);
\$pspell_link = pspell_new("en"); # set language

}

else
{
foreach (\$suggestions as \$suggestion)
{
d(\$suggestion,\$a);
e(\$suggestion,\$b);

if(c(\$suggestion,\$a) == "true")
{
if(in_array(\$suggestion,\$wordWorks))
{
//do nothing
}
else
{
\$wordWorks[] = \$suggestion;
echo \$suggestion."<br>";
}
}

}
}

}  else {
for (\$i = count(\$items) - 1; \$i >= 0; --\$i) {
usleep(2000); # slow down for CPU
\$newitems = \$items;
\$newperms = \$perms;
list(\$foo) = array_splice(\$newitems, \$i, 1);
array_unshift(\$newperms, \$foo);
pc_permute(\$newitems, \$newperms); # recursive loop
}
}

return \$workWords;

}

echo "\n";

# count and compare values between array a and word
function d(\$word, \$array)
{
global \$d;
\$u = array_unique(\$array);
\$w = str_split(\$word);

\$u2 = array_intersect(\$u,\$w);
\$a1 = array_count_values(\$array);
\$w1 = array_count_values(\$w);
\$a = array();
foreach(\$u2 as \$k => \$v)
{
\$a[] = (\$a1[\$v] >= \$w1[\$v]) ? true:false;
}

\$d = in_array(false,\$a) ? false:true;
return \$d;
}

# check array b
function e(\$word,\$barray)
{
global \$e;
\$r = array();
\$n = str_split(\$word);
\$bn = 0;
if(count(\$barray) != 0 && is_array(\$barray))
{
for(\$i = 0; \$i < count(\$n); \$i++)
{
if(in_array(\$n[\$i],\$barray))
{
if(\$bn == 0)
{
\$bn++;
\$r[] = 1;
}
else
{
\$bn++;
\$r[] = 2;
}
}
else
{
\$r[] = 3;
}
}
}
elseif(count(\$barray) == 0 && is_array(\$barray))
{
\$r[] = 1;
}
else
{
\$r[] = 0;
}

# codes:
# 0 no array
# 1 array yes, letter matched or empty array
# 2 array yes, more than one letter matched
# 3 array yes, no letter

\$e = (in_array(1,\$r) == true && in_array(2,\$r) == false) ? true:false;
return \$e;
}

# check array a
function c(\$word,\$array)
{
global \$d;
global \$e;
\$n = str_split(\$word);
\$r = array();
for(\$i = 0; \$i < count(\$n); \$i++)
{
if(in_array(\$n[\$i],\$array))
{
\$r[] = true;
}
elseif(\$e == true)
{
\$r[] = true;
}
else
{
\$r[] = false;
}
}

\$res = array();
\$res[] = \$d;
\$res[] = \$e;
\$res[] = in_array(false,\$r) ? false:true;
return in_array(false,\$res) ? 'false':'true';
}

\$c = array_merge(\$a,\$b);
pc_permute(\$c); # run
}

?>``````

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/joeb34/public_html/Scrabble-Cheater/1-0/index.php on line 54
holster
Holst
honester
holsters
holstered
construe
honest
Holst's
holster's

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/joeb34/public_html/Scrabble-Cheater/1-0/index.php on line 54
holster
Holst
honester
holsters
holstered
construe
honest
Holst's
holster's

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/joeb34/public_html/Scrabble-Cheater/1-0/index.php on line 54
holster
honester
Holst
holsters
holstered
honest
holster's

Any help would highly be appreciated! Looks like an infinite loop.

``for (\$i = count(\$items) - 1; \$i >= 0; --\$i) {``

It's not reaching -1.

Perhaps echoing \$i in the loop will show you what's going on. Maybe:

``for (\$i = count(\$items) - 1; \$i >= 0; \$i--) {``

Looks like an infinite loop.

``for (\$i = count(\$items) - 1; \$i >= 0; --\$i) {``

It's not reaching -1.

Perhaps echoing \$i in the loop will show you what's going on. Maybe:

``for (\$i = count(\$items) - 1; \$i >= 0; \$i--) {``

Okay I added the echo \$i, but it still never seems to end and it looks like this...

6543210
Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/joeb34/public_html/Scrabble-Cheater/1-0/index.php on line 54
you
yo
Yugo
duo
00
Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/joeb34/public_html/Scrabble-Cheater/1-0/index.php on line 54
you
yo
Yugo
duo
110
Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/joeb34/public_html/Scrabble-Cheater/1-0/index.php on line 54
yo
Wyo
Ugo
00
Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/joeb34/public_html/Scrabble-Cheater/1-0/index.php on line 54
yo
Wyo
Ugo
010
Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/joeb34/public_html/Scrabble-Cheater/1-0/index.php on line 54
you
yo
Yugo
duo
00
Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/joeb34/public_html/Scrabble-Cheater/1-0/index.php on line 54
yo
Wyo
Ugo
2210

This works without errors, unless input is too long and the execution time goes over 30 seconds, at that point PHP will stop the script and return part of the output and an error. For this reason I added a length check at the end of the script, otherwise you have to increase max_execution_time.

``````<?php

if(empty(\$_POST['yl']))
{
echo "<form action='index.php' method='POST'>
Your Letters: <input type='text' name='yl' value='oor'>
Board Letters: <input type='text' name='bl' value='dt'>
<input type='submit'></form>";
}
else
{
\$replace = array(',',' ','','-');
\$a = str_split(str_replace(\$replace,'',\$_POST['yl']));
\$b = str_split(str_replace(\$replace,'',\$_POST['bl']));

# removable
echo '<h5>input</h5><pre>';
print_r(\$a);
print_r(\$b);
echo '</pre>';

function pc_permute(\$items, \$perms = array( )) {

global \$a;
global \$b;
global \$d;
global \$e;

if (empty(\$items)) {
\$w = join('', \$perms);
\$pspell_link = pspell_new("en"); # set language

\$z = array();
foreach (\$suggestions as \$suggestion)
{
\$s = strtolower(\$suggestion);
d(\$s,\$a);
e(\$s,\$b);

if(c(\$s,\$a) == "true")
{
\$z[] = \$s;
}

}
\$z2 = array_unique(\$z);
foreach(\$z2 as \$wrd)
{
echo \$wrd . "<br />";
}
echo '<hr />';

}  else {
for (\$i = count(\$items) - 1; \$i >= 0; --\$i) {
usleep(2000); # slow down for CPU
\$newitems = \$items;
\$newperms = \$perms;
list(\$foo) = array_splice(\$newitems, \$i, 1);
array_unshift(\$newperms, \$foo);
pc_permute(\$newitems, \$newperms); # recursive loop
}
}

}

# count and compare values between array a and word
function d(\$word, \$array)
{
global \$d;
\$u = array_unique(\$array);
\$w = str_split(\$word);

\$u2 = array_intersect(\$u,\$w);
\$a1 = array_count_values(\$array);
\$w1 = array_count_values(\$w);
\$a = array();
foreach(\$u2 as \$k => \$v)
{
\$a[] = (\$a1[\$v] >= \$w1[\$v]) ? true:false;
}

\$d = in_array(false,\$a) ? false:true;
return \$d;
}

# check array b
function e(\$word,\$barray)
{
global \$e;
\$r = array();
\$n = str_split(\$word);
\$bn = 0;
if(count(\$barray) != 0 && is_array(\$barray))
{
for(\$i = 0; \$i < count(\$n); \$i++)
{
if(in_array(\$n[\$i],\$barray))
{
if(\$bn == 0)
{
\$bn++;
\$r[] = 1;
}
else
{
\$bn++;
\$r[] = 2;
}
}
else
{
\$r[] = 3;
}
}
}
elseif(count(\$barray) == 0 && is_array(\$barray))
{
\$r[] = 1;
}
else
{
\$r[] = 0;
}

# codes:
# 0 no array
# 1 array yes, letter matched or empty array
# 2 array yes, more than one letter matched
# 3 array yes, no letter

\$e = (in_array(1,\$r) == true && in_array(2,\$r) == false) ? true:false;
return \$e;
}

# check array a
function c(\$word,\$array)
{
global \$d;
global \$e;
\$n = str_split(\$word);
\$r = array();
for(\$i = 0; \$i < count(\$n); \$i++)
{
if(in_array(\$n[\$i],\$array))
{
\$r[] = true;
}
elseif(\$e == true)
{
\$r[] = true;
}
else
{
\$r[] = false;
}
}

\$res = array();
\$res[] = \$d;
\$res[] = \$e;
\$res[] = in_array(false,\$r) ? false:true;
return in_array(false,\$res) ? 'false':'true';
}

\$c = array_merge(\$a,\$b);
if(count(\$c) > 5) # check length
{
echo 'too long';
}
else
{
pc_permute(\$c); # run also with pc_permute(\$a,\$b)
}
}

?>``````

Is this the output you are searching for? I'm still in doubt.. hehe :D

P.S. also consider for Pritaeas suggestion, something in C# or C++ may be hugely faster than PHP: http://www.daniweb.com/web-development/javascript-dhtml-ajax/threads/408526/1748151#post1748151

This works without errors, unless input is too long and the execution time goes over 30 seconds, at that point PHP will stop the script and return part of the output and an error. For this reason I added a length check at the end of the script, otherwise you have to increase max_execution_time.

``````<?php

if(empty(\$_POST['yl']))
{
echo "<form action='index.php' method='POST'>
Your Letters: <input type='text' name='yl' value='oor'>
Board Letters: <input type='text' name='bl' value='dt'>
<input type='submit'></form>";
}
else
{
\$replace = array(',',' ','','-');
\$a = str_split(str_replace(\$replace,'',\$_POST['yl']));
\$b = str_split(str_replace(\$replace,'',\$_POST['bl']));

# removable
echo '<h5>input</h5><pre>';
print_r(\$a);
print_r(\$b);
echo '</pre>';

function pc_permute(\$items, \$perms = array( )) {

global \$a;
global \$b;
global \$d;
global \$e;

if (empty(\$items)) {
\$w = join('', \$perms);
\$pspell_link = pspell_new("en"); # set language

\$z = array();
foreach (\$suggestions as \$suggestion)
{
\$s = strtolower(\$suggestion);
d(\$s,\$a);
e(\$s,\$b);

if(c(\$s,\$a) == "true")
{
\$z[] = \$s;
}

}
\$z2 = array_unique(\$z);
foreach(\$z2 as \$wrd)
{
echo \$wrd . "<br />";
}
echo '<hr />';

}  else {
for (\$i = count(\$items) - 1; \$i >= 0; --\$i) {
usleep(2000); # slow down for CPU
\$newitems = \$items;
\$newperms = \$perms;
list(\$foo) = array_splice(\$newitems, \$i, 1);
array_unshift(\$newperms, \$foo);
pc_permute(\$newitems, \$newperms); # recursive loop
}
}

}

# count and compare values between array a and word
function d(\$word, \$array)
{
global \$d;
\$u = array_unique(\$array);
\$w = str_split(\$word);

\$u2 = array_intersect(\$u,\$w);
\$a1 = array_count_values(\$array);
\$w1 = array_count_values(\$w);
\$a = array();
foreach(\$u2 as \$k => \$v)
{
\$a[] = (\$a1[\$v] >= \$w1[\$v]) ? true:false;
}

\$d = in_array(false,\$a) ? false:true;
return \$d;
}

# check array b
function e(\$word,\$barray)
{
global \$e;
\$r = array();
\$n = str_split(\$word);
\$bn = 0;
if(count(\$barray) != 0 && is_array(\$barray))
{
for(\$i = 0; \$i < count(\$n); \$i++)
{
if(in_array(\$n[\$i],\$barray))
{
if(\$bn == 0)
{
\$bn++;
\$r[] = 1;
}
else
{
\$bn++;
\$r[] = 2;
}
}
else
{
\$r[] = 3;
}
}
}
elseif(count(\$barray) == 0 && is_array(\$barray))
{
\$r[] = 1;
}
else
{
\$r[] = 0;
}

# codes:
# 0 no array
# 1 array yes, letter matched or empty array
# 2 array yes, more than one letter matched
# 3 array yes, no letter

\$e = (in_array(1,\$r) == true && in_array(2,\$r) == false) ? true:false;
return \$e;
}

# check array a
function c(\$word,\$array)
{
global \$d;
global \$e;
\$n = str_split(\$word);
\$r = array();
for(\$i = 0; \$i < count(\$n); \$i++)
{
if(in_array(\$n[\$i],\$array))
{
\$r[] = true;
}
elseif(\$e == true)
{
\$r[] = true;
}
else
{
\$r[] = false;
}
}

\$res = array();
\$res[] = \$d;
\$res[] = \$e;
\$res[] = in_array(false,\$r) ? false:true;
return in_array(false,\$res) ? 'false':'true';
}

\$c = array_merge(\$a,\$b);
if(count(\$c) > 5) # check length
{
echo 'too long';
}
else
{
pc_permute(\$c); # run also with pc_permute(\$a,\$b)
}
}

?>``````

Is this the output you are searching for? I'm still in doubt.. hehe :D

P.S. also consider for Pritaeas suggestion, something in C# or C++ may be hugely faster than PHP: http://www.daniweb.com/web-development/javascript-dhtml-ajax/threads/408526/1748151#post1748151

Thanks for the reply. That still isn't what I'm looking for. You see, I don't really want the words to repeat. With your code here is the beginning of my output...

Notice that Bord and Bord repeats. I want no repeats...

input

Array
(
 => o
 => o
 => r
)
Array
(
 => d
)
bord
cord
ford
lord
mord
word
bord
cord
ford
lord
mord
word
rood
prod
rod
brod
trod

Ok, I changed permutation function, it's taken always from that article: http://docstore.mik.ua/orelly/webprog/pcook/ch04_26.htm
Previously it was hard to return the output from the function, now I created a class:

``````<?php
# filename perm.class.php
Class Perm
{

public function start(\$arrayA,\$arrayB)
{
\$c = array_merge(\$arrayA,\$arrayB);

if(count(\$c) > 5)
{
return 'too long';
}
else
{
\$size = count(\$c)-1;
\$perm = range(0, \$size);
\$j = 0;

do {
foreach (\$perm as \$i) { \$perms[\$j][] = \$c[\$i]; }
} while (\$perm = \$this->p(\$perm, \$size) and ++\$j);

\$list = array();
foreach (\$perms as \$p) {
\$list[] = join('', \$p);
}

return array_unique(\$this->ps(\$list));
}
}

# generate permutations
private function p(\$p, \$size) {
for (\$i = \$size-1; @\$p[\$i] >= \$p[\$i+1]; --\$i) { }
if (\$i == -1) { return false; }
for (\$j = \$size; \$p[\$j] <= \$p[\$i]; --\$j) { }

\$tmp = \$p[\$i];
\$p[\$i] = \$p[\$j];
\$p[\$j] = \$tmp;

for (++\$i, \$j = \$size; \$i < \$j; ++\$i, --\$j) {
\$tmp = \$p[\$i];
\$p[\$i] = \$p[\$j];
\$p[\$j] = \$tmp;
}

return \$p;
}

# count and compare values between array a and word
private function d(\$word, \$array)
{
global \$d;
\$u = array_unique(\$array);
\$w = str_split(\$word);

\$u2 = array_intersect(\$u,\$w);
\$a1 = array_count_values(\$array);
\$w1 = array_count_values(\$w);
\$a = array();
foreach(\$u2 as \$k => \$v)
{
\$a[] = (\$a1[\$v] >= \$w1[\$v]) ? true:false;
}

\$d = in_array(false,\$a) ? false:true;
return \$d;
}

# check array b
private function e(\$word,\$barray)
{
global \$e;
\$r = array();
\$n = str_split(\$word);
\$bn = 0;
if(count(\$barray) != 0 && is_array(\$barray))
{
for(\$i = 0; \$i < count(\$n); \$i++)
{
if(in_array(\$n[\$i],\$barray))
{
if(\$bn == 0)
{
\$bn++;
\$r[] = 1;
}
else
{
\$bn++;
\$r[] = 2;
}
}
else
{
\$r[] = 3;
}
}
}
elseif(count(\$barray) == 0 && is_array(\$barray))
{
\$r[] = 1;
}
else
{
\$r[] = 0;
}

# codes:
# 0 no array
# 1 array yes, letter matched or empty array
# 2 array yes, more than one letter matched
# 3 array yes, no letter

\$e = (in_array(1,\$r) == true && in_array(2,\$r) == false) ? true:false;
return \$e;
}

# removable, just test message
public function mess()
{
return 'hello world';
}

# check array a
private function c(\$word,\$array)
{
global \$d;
global \$e;
global \$result;
\$n = str_split(\$word);
\$r = array();
for(\$i = 0; \$i < count(\$n); \$i++)
{
if(in_array(\$n[\$i],\$array))
{
\$r[] = true;
}
elseif(\$e == true)
{
\$r[] = true;
}
else
{
\$r[] = false;
}
}

\$res = array();
\$res[] = \$d;
\$res[] = \$e;
\$res[] = in_array(false,\$r) ? false:true;
\$result = in_array(false,\$res) ? false:true;
return \$result;
}

# check real words
private function ps(\$list)
{
global \$a;
global \$b;
\$n = count(\$list);
\$pspell_link = pspell_new("en"); # set language
\$z = array();
for(\$i = 0; \$i < \$n; \$i++)
{
foreach (\$suggestions as \$suggestion)
{
if(strlen(\$suggestion) > 1)
{
\$s = strtolower(\$suggestion);
\$this->d(\$s,\$a);
\$this->e(\$s,\$b);

if(\$this->c(\$s,\$a) == true)
{
\$z[] = \$s;
}
}

}
}
return \$z;
}
}
?>``````

And this is the page where you have to include the class:

``````<?php
include 'perm.class.php'; # include class

# page outputs

if(empty(\$_POST['yl']))
{
echo "<form action='n.php' method='POST'>
Your Letters: <input type='text' name='yl' value='oor'>
Board Letters: <input type='text' name='bl' value='dt'>
<input type='submit'></form>";
}
else
{
\$replace = array(',',' ','','-');
\$a = str_split(str_replace(\$replace,'',\$_POST['yl']));
\$b = str_split(str_replace(\$replace,'',\$_POST['bl']));
echo '<h5>input</h5><pre>';
print_r(\$a);
print_r(\$b);
echo '</pre>';

# start
\$play = new Perm();
echo '<pre>';
print_r(\$play->start(\$a,\$b)); # you only need this to get results
echo '</pre>';
}
?>``````

Files are attached, the only problem is:

``Notice: Undefined offset: -1 in /var/www/test/m/perm.class.php on line 35``

which is not shown because I placed a @ (booo on me), but right now I just can't get that straight.. too tired ^_^

Just an add, on line 178 of the class you can change the conditional statement to:

``if(\$this->c(\$s,\$a) == true && ctype_alpha(\$s))``

this will remove results like root's, odor's and the others.

Just an add, on line 178 of the class you can change the conditional statement to:

``if(\$this->c(\$s,\$a) == true && ctype_alpha(\$s))``

this will remove results like root's, odor's and the others.

One last problem. If I don't put in a character in the board letters text box nothing comes back.

I would like (if there are no letters in the \$b array) for it to find as many words as possible using just the \$a array.

Great job!

One last problem. If I don't put in a character in the board letters text box nothing comes back.

I would like (if there are no letters in the \$b array) for it to find as many words as possible using just the \$a array.

Great job!

Wait, it's not quite working any more. I put in this...

Board Letters: o

And I got these results...

None of them work...

cosed - 8
justino - 14
gusto - 6
castro - 8
giusto - 7
castor - 8
ghost - 9
gestapo - 10
gustavo - 11
cost - 10
kudos - 4
sod - 7
isidor - 9
pseudo - 5
soda - 12
judo - 3
sot - 6
misdo - 7
scot - 16
stow - 16
guido - 13
cowhide - 15
cowherd - 16
suharto - 7
cuspidor - 9
coxed - 9
custody - 11
exhort - 10
costa - 8
sword - 5
swot - 7
sowed - 11
keyword - 7
cowed - 13
resowed - 7
gaston - 16
custom - 14
stowe - 11
caxton - 6
keystone - 12
postwar - 7
guizot - 12
joist - 8
joust - 8

Another thing I changed was line 10 of the class...

``if(count(\$c) > 100)``

AND n.php...

``````<?php
include 'perm.class.php'; # include class

# page outputs

function scoreit(\$c,\$x)
{
if(\$c == "a")
{
\$x = \$x + 1;
}

if(\$c == "b")
{
\$x = \$x + 3;
}

if(\$c == "c")
{
\$x = \$x + 3;
}

if(\$c == "d")
{
\$x = \$x + 2;
}

if(\$c == "e")
{
\$x = \$x + 1;
}

if(\$c == "f")
{
\$x = \$x + 4;
}

if(\$c == "g")
{
\$x = \$x + 2;
}
if(\$c == "h")
{
\$x = \$x + 4;
}

if(\$c == "i")
{
\$x = \$x + 1;
}

if(\$c == "j")
{
\$x = \$x + 8;
}

if(\$c == "k")
{
\$x = \$x + 5;
}

if(\$c == "l")
{
\$x = \$x + 1;
}

if(\$c == "m")
{
\$x = \$x + 3;
}

if(\$c == "n")
{
\$x = \$x + 1;
}

if(\$c == "o")
{
\$x = \$x + 1;
}

if(\$c == "p")
{
\$x = \$x + 3;
}

if(\$c == "q")
{
\$x = \$x + 10;
}

if(\$c == "r")
{
\$x = \$x + 1;
}

if(\$c == "s")
{
\$x = \$x + 1;
}

if(\$c == "t")
{
\$x = \$x + 1;
}

if(\$c == "u")
{
\$x = \$x + 1;
}

if(\$c == "v")
{
\$x = \$x + 4;
}

if(\$c == "w")
{
\$x = \$x + 4;
}

if(\$c == "x")
{
\$x = \$x + 8;
}

if(\$c == "y")
{
\$x = \$x + 4;
}

if(\$c == "z")
{
\$x = \$x + 10;
}

return \$x;
}

if(empty(\$_POST['yl']))
{

}
else
{
\$replace = array(',',' ','','-');
\$a = str_split(str_replace(\$replace,'',\$_POST['yl']));
\$b = str_split(str_replace(\$replace,'',\$_POST['bl']));

# start
\$play = new Perm();
echo '<pre>';
\$worknWords = \$play->start(\$a,\$b); # you only need this to get results
\$worknRatings = array();
\$x = 0;
foreach(\$worknWords as \$word)
{
\$eachLetter = str_split(\$word);

foreach(\$eachLetter as \$char)
{
\$x = scoreit(\$char,\$x);
}

\$worknRatings[] = \$x;
\$x = 0; //reset
}

for(\$i = 0; \$i < count(\$worknWords); \$i++)
{
if(\$worknWords[\$i] != "")
{
echo \$worknWords[\$i]." - ".\$worknRatings[\$i]."<br>";
}
}
echo '</pre>';
}
?>``````

Wait, one problem at a time.
An update on the class:

``````<?php
Class Perm
{

public function start(\$arrayA,\$arrayB)
{
global \$a;
global \$b;

\$replace = array(',',' ','','-');
\$a = str_split(str_replace(\$replace,'',\$arrayA));

if(empty(\$arrayB))
{
\$bArr = false;
\$b = array();
} else {
\$bArr = true;
\$b = str_split(str_replace(\$replace,'',\$arrayB));
}

\$c = (\$bArr == false) ? \$a : array_merge(\$a,\$b);

if(count(\$c) > 5)
{
return 'too long';
}
else
{
\$size = count(\$c)-1;
\$perm = range(0, \$size);
\$j = 0;

do {
foreach (\$perm as \$i) { \$perms[\$j][] = \$c[\$i]; }
} while (\$perm = \$this->p(\$perm, \$size) and ++\$j);

\$list = array();
foreach (\$perms as \$p) {
\$list[] = join('', \$p);
}

return array_unique(\$this->ps(\$list));
}
}

# generate permutations
private function p(\$p, \$size) {
for (\$i = \$size-1; @\$p[\$i] >= \$p[\$i+1]; --\$i) { }
if (\$i == -1) { return false; }
for (\$j = \$size; \$p[\$j] <= \$p[\$i]; --\$j) { }

\$tmp = \$p[\$i];
\$p[\$i] = \$p[\$j];
\$p[\$j] = \$tmp;

for (++\$i, \$j = \$size; \$i < \$j; ++\$i, --\$j) {
\$tmp = \$p[\$i];
\$p[\$i] = \$p[\$j];
\$p[\$j] = \$tmp;
}

return \$p;
}

# count and compare values between array a and word
private function d(\$word, \$array)
{
global \$d;
\$u = array_unique(\$array);
\$w = str_split(\$word);

\$u2 = array_intersect(\$u,\$w);
\$a1 = array_count_values(\$array);
\$w1 = array_count_values(\$w);
\$a = array();
foreach(\$u2 as \$k => \$v)
{
\$a[] = (\$a1[\$v] >= \$w1[\$v]) ? true:false;
}

\$d = in_array(false,\$a) ? false:true;
return \$d;
}

# check array b
private function e(\$word,\$barray)
{
global \$e;
\$r = array();
\$n = str_split(\$word);
\$bn = 0;
if(count(\$barray) != 0 && is_array(\$barray))
{
for(\$i = 0; \$i < count(\$n); \$i++)
{
if(in_array(\$n[\$i],\$barray))
{
if(\$bn == 0)
{
\$bn++;
\$r[] = 1;
}
else
{
\$bn++;
\$r[] = 2;
}
}
else
{
\$r[] = 3;
}
}
}
elseif(count(\$barray) == 0 && is_array(\$barray))
{
\$r[] = 1;
}
else
{
\$r[] = 0;
}

# codes:
# 0 no array
# 1 array yes, letter matched or empty array
# 2 array yes, more than one letter matched
# 3 array yes, no letter

\$e = (in_array(1,\$r) == true && in_array(2,\$r) == false) ? true:false;
return \$e;
}

# check array a
private function c(\$word,\$array)
{
global \$d;
global \$e;
global \$result;
\$n = str_split(\$word);
\$r = array();
for(\$i = 0; \$i < count(\$n); \$i++)
{
if(in_array(\$n[\$i],\$array))
{
\$r[] = true;
}
elseif(\$e == true)
{
\$r[] = true;
}
else
{
\$r[] = false;
}
}

\$res = array();
\$res[] = \$d;
\$res[] = \$e;
\$res[] = in_array(false,\$r) ? false:true;
\$result = in_array(false,\$res) ? false:true;
return \$result;
}

# check real words
private function ps(\$list)
{
global \$a;
global \$b;
\$n = count(\$list);
\$pspell_link = pspell_new("en"); # set language
\$z = array();
for(\$i = 0; \$i < \$n; \$i++)
{
foreach (\$suggestions as \$suggestion)
{
if(strlen(\$suggestion) > 1)
{
\$s = strtolower(\$suggestion);
\$this->d(\$s,\$a);
\$this->e(\$s,\$b);

if(\$this->c(\$s,\$a) == true && ctype_alpha(\$s))
{
\$z[] = \$s;
}
}

}
}
return \$z;
}
}
?>``````

New input page is simplified:

``````<?php
include 'perm.class.php';

# page outputs

if(empty(\$_POST['yl']))
{
echo "<form action='n.php' method='POST'>
Your Letters: <input type='text' name='yl' value='oor'>
Board Letters: <input type='text' name='bl' value='dt'>
<input type='submit'></form>";
}
else
{
\$a = \$_POST['yl'];
\$b = \$_POST['bl'];
\$play = new Perm();
echo '<pre>';
print_r(\$play->start(\$a,\$b));
echo '</pre>';
}
?>``````

Now: what is not working for you, explain me please.

Wait, one problem at a time.
An update on the class:

``````<?php
Class Perm
{

public function start(\$arrayA,\$arrayB)
{
global \$a;
global \$b;

\$replace = array(',',' ','','-');
\$a = str_split(str_replace(\$replace,'',\$arrayA));

if(empty(\$arrayB))
{
\$bArr = false;
\$b = array();
} else {
\$bArr = true;
\$b = str_split(str_replace(\$replace,'',\$arrayB));
}

\$c = (\$bArr == false) ? \$a : array_merge(\$a,\$b);

if(count(\$c) > 5)
{
return 'too long';
}
else
{
\$size = count(\$c)-1;
\$perm = range(0, \$size);
\$j = 0;

do {
foreach (\$perm as \$i) { \$perms[\$j][] = \$c[\$i]; }
} while (\$perm = \$this->p(\$perm, \$size) and ++\$j);

\$list = array();
foreach (\$perms as \$p) {
\$list[] = join('', \$p);
}

return array_unique(\$this->ps(\$list));
}
}

# generate permutations
private function p(\$p, \$size) {
for (\$i = \$size-1; @\$p[\$i] >= \$p[\$i+1]; --\$i) { }
if (\$i == -1) { return false; }
for (\$j = \$size; \$p[\$j] <= \$p[\$i]; --\$j) { }

\$tmp = \$p[\$i];
\$p[\$i] = \$p[\$j];
\$p[\$j] = \$tmp;

for (++\$i, \$j = \$size; \$i < \$j; ++\$i, --\$j) {
\$tmp = \$p[\$i];
\$p[\$i] = \$p[\$j];
\$p[\$j] = \$tmp;
}

return \$p;
}

# count and compare values between array a and word
private function d(\$word, \$array)
{
global \$d;
\$u = array_unique(\$array);
\$w = str_split(\$word);

\$u2 = array_intersect(\$u,\$w);
\$a1 = array_count_values(\$array);
\$w1 = array_count_values(\$w);
\$a = array();
foreach(\$u2 as \$k => \$v)
{
\$a[] = (\$a1[\$v] >= \$w1[\$v]) ? true:false;
}

\$d = in_array(false,\$a) ? false:true;
return \$d;
}

# check array b
private function e(\$word,\$barray)
{
global \$e;
\$r = array();
\$n = str_split(\$word);
\$bn = 0;
if(count(\$barray) != 0 && is_array(\$barray))
{
for(\$i = 0; \$i < count(\$n); \$i++)
{
if(in_array(\$n[\$i],\$barray))
{
if(\$bn == 0)
{
\$bn++;
\$r[] = 1;
}
else
{
\$bn++;
\$r[] = 2;
}
}
else
{
\$r[] = 3;
}
}
}
elseif(count(\$barray) == 0 && is_array(\$barray))
{
\$r[] = 1;
}
else
{
\$r[] = 0;
}

# codes:
# 0 no array
# 1 array yes, letter matched or empty array
# 2 array yes, more than one letter matched
# 3 array yes, no letter

\$e = (in_array(1,\$r) == true && in_array(2,\$r) == false) ? true:false;
return \$e;
}

# check array a
private function c(\$word,\$array)
{
global \$d;
global \$e;
global \$result;
\$n = str_split(\$word);
\$r = array();
for(\$i = 0; \$i < count(\$n); \$i++)
{
if(in_array(\$n[\$i],\$array))
{
\$r[] = true;
}
elseif(\$e == true)
{
\$r[] = true;
}
else
{
\$r[] = false;
}
}

\$res = array();
\$res[] = \$d;
\$res[] = \$e;
\$res[] = in_array(false,\$r) ? false:true;
\$result = in_array(false,\$res) ? false:true;
return \$result;
}

# check real words
private function ps(\$list)
{
global \$a;
global \$b;
\$n = count(\$list);
\$pspell_link = pspell_new("en"); # set language
\$z = array();
for(\$i = 0; \$i < \$n; \$i++)
{
foreach (\$suggestions as \$suggestion)
{
if(strlen(\$suggestion) > 1)
{
\$s = strtolower(\$suggestion);
\$this->d(\$s,\$a);
\$this->e(\$s,\$b);

if(\$this->c(\$s,\$a) == true && ctype_alpha(\$s))
{
\$z[] = \$s;
}
}

}
}
return \$z;
}
}
?>``````

New input page is simplified:

``````<?php
include 'perm.class.php';

# page outputs

if(empty(\$_POST['yl']))
{
echo "<form action='n.php' method='POST'>
Your Letters: <input type='text' name='yl' value='oor'>
Board Letters: <input type='text' name='bl' value='dt'>
<input type='submit'></form>";
}
else
{
\$a = \$_POST['yl'];
\$b = \$_POST['bl'];
\$play = new Perm();
echo '<pre>';
print_r(\$play->start(\$a,\$b));
echo '</pre>';
}
?>``````

Now: what is not working for you, explain me please.

Thanks for all of your help. I still have letters that were not included in the text boxes though. Thanks!

Update class function ps() with this:

``````private function ps(\$list)
{
global \$a;
global \$b;
\$n = count(\$list);
\$pspell_config = pspell_config_create("en");

# Available flags:
#
# PSPELL_FAST
# PSPELL_NORMAL
# PSPELL_BAD_SPELLERS # this will slow down the script
#
\$z = array();
for(\$i = 0; \$i < \$n; \$i++)
{
foreach (\$suggestions as \$suggestion)
{
if(strlen(\$suggestion) > 1)
{
\$s = strtolower(\$suggestion);
\$this->d(\$s,\$a);
\$this->e(\$s,\$b);

if(\$this->c(\$s,\$a) == true && ctype_alpha(\$s))
{
\$z[] = \$s;
}
}

}
}
return \$z;
}``````

You can increase results by setting flags in pspell config as explained here: http://www.php.net/manual/en/function.pspell-config-mode.php
If it still doesn't match, please provide an example. Bye :)

Update class function ps() with this:

``````private function ps(\$list)
{
global \$a;
global \$b;
\$n = count(\$list);
\$pspell_config = pspell_config_create("en");

# Available flags:
#
# PSPELL_FAST
# PSPELL_NORMAL
# PSPELL_BAD_SPELLERS # this will slow down the script
#
\$z = array();
for(\$i = 0; \$i < \$n; \$i++)
{
foreach (\$suggestions as \$suggestion)
{
if(strlen(\$suggestion) > 1)
{
\$s = strtolower(\$suggestion);
\$this->d(\$s,\$a);
\$this->e(\$s,\$b);

if(\$this->c(\$s,\$a) == true && ctype_alpha(\$s))
{
\$z[] = \$s;
}
}

}
}
return \$z;
}``````

You can increase results by setting flags in pspell config as explained here: http://www.php.net/manual/en/function.pspell-config-mode.php
If it still doesn't match, please provide an example. Bye :)

It still didn't work...

I entered in "rd" and "e" and got these results...

It shouldn't contain letters that weren't entered.

 => red
 => ride
 => rode
 => rude
 => rte
 => redo
 => rued
 => rodie
 => rudie
 => rodeo
 => rate
 => rite
 => rote
 => dre
 => de
 => re
 => rae
 => roe
 => rue
 => ode
 => rye
 => wried
 => reit
 => reid
 => reta
 => rhodie
 => rheta
 => rhett
 => route
 => write
 => wrote
 => drew
 => fred
 => bred
 => cred
 => ired
 => reds

So if you set rde you want to get only:

``````Array
(
 => red
 => dre
 => de
 => re
 => ed
 => der
 => er
)``````

Am I right? If yes maybe we got it, now there is a function at the end, that will check only for words containing set letters:

``````<?php
Class Perm
{

public function start(\$arrayA,\$arrayB)
{
global \$a;
global \$b;
global \$c;

\$replace = array(',',' ','','-');
\$a = str_split(str_replace(\$replace,'',\$arrayA));

if(empty(\$arrayB))
{
\$bArr = false;
\$b = array();
} else {
\$bArr = true;
\$b = str_split(str_replace(\$replace,'',\$arrayB));
}

\$c = (\$bArr == false) ? \$a : array_merge(\$a,\$b);

if(count(\$c) > 5)
{
return 'too long';
}
elseif(count(\$c) <= 1)
{
return 'too short';
}
else
{
\$size = count(\$c)-1;
\$perm = range(0, \$size);
\$j = 0;

do {
foreach (\$perm as \$i) { \$perms[\$j][] = \$c[\$i]; }
} while (\$perm = \$this->p(\$perm, \$size) and ++\$j);

\$list = array();
foreach (\$perms as \$p) {
\$list[] = join('', \$p);
}

return array_unique(\$this->ps(\$list));
}
}

# generate permutations
private function p(\$p, \$size) {
for (\$i = \$size-1; @\$p[\$i] >= \$p[\$i+1]; --\$i) { }
if (\$i == -1) { return false; }
for (\$j = \$size; \$p[\$j] <= \$p[\$i]; --\$j) { }

\$tmp = \$p[\$i];
\$p[\$i] = \$p[\$j];
\$p[\$j] = \$tmp;

for (++\$i, \$j = \$size; \$i < \$j; ++\$i, --\$j) {
\$tmp = \$p[\$i];
\$p[\$i] = \$p[\$j];
\$p[\$j] = \$tmp;
}

return \$p;
}

# count and compare values between array a and word
private function d(\$word, \$array)
{
global \$d;
\$u = array_unique(\$array);
\$w = str_split(\$word);

\$u2 = array_intersect(\$u,\$w);
\$a1 = array_count_values(\$array);
\$w1 = array_count_values(\$w);
\$a = array();
foreach(\$u2 as \$k => \$v)
{
\$a[] = (\$a1[\$v] >= \$w1[\$v]) ? true:false;
}

\$d = in_array(false,\$a) ? false:true;
return \$d;
}

# check array b
private function e(\$word,\$barray)
{
global \$e;
\$r = array();
\$n = str_split(\$word);
\$bn = 0;
if(count(\$barray) != 0 && is_array(\$barray))
{
for(\$i = 0; \$i < count(\$n); \$i++)
{
if(in_array(\$n[\$i],\$barray))
{
if(\$bn == 0)
{
\$bn++;
\$r[] = 1;
}
else
{
\$bn++;
\$r[] = 2;
}
}
else
{
\$r[] = 3;
}
}
}
elseif(count(\$barray) == 0 && is_array(\$barray))
{
\$r[] = 1;
}
else
{
\$r[] = 0;
}

# codes:
# 0 no array
# 1 array yes, letter matched or empty array
# 2 array yes, more than one letter matched
# 3 array yes, no letter

\$e = (in_array(1,\$r) == true && in_array(2,\$r) == false) ? true:false;
return \$e;
}

# check array a
private function c(\$word,\$array)
{
global \$d;
global \$e;
global \$result;
\$n = str_split(\$word);
\$r = array();
\$from = array();
for(\$i = 0; \$i < count(\$n); \$i++)
{
if(in_array(\$n[\$i],\$array))
{
\$r[] = true;
}
elseif(\$e == true)
{
\$r[] = true;
}
else
{
\$r[] = false;
}
}

\$res = array();
\$res[] = \$d;
\$res[] = \$e;
\$res[] = in_array(false,\$r) ? false:true;
\$result = in_array(false,\$res) ? false:true;
return \$result;
}

# get suggestions
private function ps(\$list)
{
global \$a;
global \$b;
\$n = count(\$list);
\$pspell_config = pspell_config_create("en");

# Available modes:
#
# PSPELL_FAST
# PSPELL_NORMAL
# PSPELL_BAD_SPELLERS # this will slow down the script
#
pspell_config_mode(\$pspell_config, PSPELL_FAST);
\$z = array();
for(\$i = 0; \$i < \$n; \$i++)
{
foreach (\$suggestions as \$suggestion)
{
if(strlen(\$suggestion) > 1)
{
\$s = strtolower(\$suggestion);
\$this->d(\$s,\$a);
\$this->e(\$s,\$b);

if(\$this->c(\$s,\$a) == true && ctype_alpha(\$s) && \$this->check(\$s) == true)
{
\$z[] = \$s;
}
}

}
}
return \$z;
}

# filter
private function check(\$word)
{
global \$c;
\$w = str_split(\$word);
\$chklst = array();
for(\$i = 0; \$i < count(\$w); \$i++)
{
\$chklst[] = (in_array(\$w[\$i],\$c)) ? true:false;
}
return in_array(false,\$chklst) ? false:true;
}

}
?>``````

Just an update on function start() this will speed up the execution and use less memory:

``````public function start(\$arrayA,\$arrayB)
{
global \$a;
global \$b;
global \$c;

\$replace = array(',',' ','','-');
\$a = str_split(str_replace(\$replace,'',\$arrayA));

if(empty(\$arrayB))
{
\$bArr = false;
\$b = array();
} else {
\$bArr = true;
\$b = str_split(str_replace(\$replace,'',\$arrayB));
}

\$c = (\$bArr == false) ? \$a : array_merge(\$a,\$b);

if(count(\$c) > 5)
{
return 'too long';
}
elseif(count(\$c) <= 1)
{
return 'too short';
}
else
{
\$size = count(\$c)-1;
\$perm = range(0, \$size);
\$j = 0;

do
{
foreach (\$perm as \$i) { \$perms[\$j][] = \$c[\$i]; }
}
while(\$perm = \$this->p(\$perm, \$size) and ++\$j);

\$list = array_map('join',\$perms);
\$list = array_unique(\$list);
\$list = array_merge(array(),\$list);
\$list = array_unique(\$this->ps(\$list));
\$result = array_merge(array(),\$list);

return \$result;
}
}``````

The permutation function p() creates a lot of duplicates, so using `\$list = array_unique(\$list);` helps to reduce data sent to function ps(). Bye.

Just an update on function start() this will speed up the execution and use less memory:

``````public function start(\$arrayA,\$arrayB)
{
global \$a;
global \$b;
global \$c;

\$replace = array(',',' ','','-');
\$a = str_split(str_replace(\$replace,'',\$arrayA));

if(empty(\$arrayB))
{
\$bArr = false;
\$b = array();
} else {
\$bArr = true;
\$b = str_split(str_replace(\$replace,'',\$arrayB));
}

\$c = (\$bArr == false) ? \$a : array_merge(\$a,\$b);

if(count(\$c) > 5)
{
return 'too long';
}
elseif(count(\$c) <= 1)
{
return 'too short';
}
else
{
\$size = count(\$c)-1;
\$perm = range(0, \$size);
\$j = 0;

do
{
foreach (\$perm as \$i) { \$perms[\$j][] = \$c[\$i]; }
}
while(\$perm = \$this->p(\$perm, \$size) and ++\$j);

\$list = array_map('join',\$perms);
\$list = array_unique(\$list);
\$list = array_merge(array(),\$list);
\$list = array_unique(\$this->ps(\$list));
\$result = array_merge(array(),\$list);

return \$result;
}
}``````

The permutation function p() creates a lot of duplicates, so using `\$list = array_unique(\$list);` helps to reduce data sent to function ps(). Bye.

Thanks Cereal. You've been really helpful!

You're welcome, bye :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.