Jump to content

array question (compare values)


Anti-Moronic

Recommended Posts

this can be intensive especially on large arrays...

 

the functions to compare strings you will be interested are:

 

http://uk3.php.net/manual/en/function.levenshtein.php

 

and

 

http://uk3.php.net/manual/en/function.similar-text.php

 

if you needed to compare each string against every other string in your array then you would need to build the appropriate loop; something like

 

<?php
$strings = array("i am a string", "i am a zebra","i am not a string","i am a wildebeast","i am a thread","i am a matrix");

$string_no = count($strings);

$compare = array();
for($i=0; $i<$string_no; $i++)
{
  if ($i == ($string_no-1)) break;
  for($k=$i+1; $k<$string_no;$k++)
  {
    $compare['strings'][] = $i . ' - ' . $k;
    $compare['likeness'][] = levenshtein($strings[$i],$strings[$k]);
  }
}

print_r($compare);
?>

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.