# glob() problem for arrays.. HELP!...

2 replies to this topic

### #1 thyscorpion

thyscorpion
• Members
• 46 posts

Posted 25 July 2006 - 09:49 AM

hi.
i was trying to use the following code to work of levenshtein()
```<?php
// input misspelled word
\$input = 'carrrot';

// array of words to check against
\$words  = array('apple','pineapple','banana','orange',

// no shortest distance found, yet
\$shortest = -1;

// loop through words to find the closest
foreach (\$words as \$word) {

// calculate the distance between the input word,
// and the current word
\$lev = levenshtein(\$input, \$word);

// check for an exact match
if (\$lev == 0) {

// closest word is this one (exact match)
\$closest = \$word;
\$shortest = 0;

// break out of the loop; we've found an exact match
break;
}

// if this distance is less than the next found shortest
// distance, OR if a next shortest word has not yet been found
if (\$lev <= \$shortest || \$shortest < 0) {
// set the closest match, and shortest distance
\$closest  = \$word;
\$shortest = \$lev;
}
}

echo "Input word: \$input\n";
if (\$shortest == 0) {
echo "Exact match found: \$closest\n";
} else {
echo "Did you mean: \$closest?\n";
}

?>```

but when instead of the array line:
```\$words  = array('apple','pineapple','banana','orange',
if i use:
```\$searchresults = array(glob("*.txt"));
```
i get an Output like:
"Did you mean: Array?"
where instead of the Array word it is supposed to print out the value in \$closest! plz help..
i am in a fix with it..

### #2 Kris

Kris
• Staff Alumni
• 2,755 posts
• LocationThe Internet

Posted 25 July 2006 - 10:17 AM

Try:
`\$searchresults = glob("*.txt");`
glob() returns its output as an array.

thyscorpion
• Members