Re: How I can find longest common prefix of strings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



ayk_amanov wrote:

> I'm interested in such algorithm that solves problem of finding longest 
> common prefix of two or more strings.

Hi Aybek,

This function should do it.

<?php

function find_longest_prefix($a, $b) {

   $i = 0;
   $ret = '';

   while ($a[$i] == $b[$i]) {
     $ret .= $a[$i++];
   }

   return $ret;

}

?>

--
Rajesh


------------------------ Yahoo! Groups Sponsor --------------------~--> 
See what's inside the new Yahoo! Groups email.
http://us.click.yahoo.com/2pRQfA/bOaOAA/yQLSAA/saFolB/TM
--------------------------------------------------------------------~-> 

PHP Data object relational mapping generator
http://www.metastorage.net/ 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php-objects/

<*> To unsubscribe from this group, send an email to:
    php-objects-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux