Reply to Re: Looping through array

Your name:

Reply:


Posted by Steve on 02/23/07 04:09

| function inTrail($path, $trail)
| {
| if (!is_array($trail)){ return ''; }
| if (!strlen($path)){ return ''; }
| $match = '';
| $path = explode('/', $path);
| $length = count($trail);
| for ($i = 0; $i < $length; $i++)
| {
| if ($path[$i] != $trail[$i]){ break; }
| $match .= $path[$i] . '/';
| }
| return $match;
| }

i just noticed that $trail is not an exploded path but an array of strings
representing paths. that's an interesting delima because you can have
similar values (paths)...so which should be correct? to make it easy, you
could just do this in your while loop (suppose i should have just kept it
simple ;^):

while (true)
{
if (in_array($path, $trail){ return $path; }
$length = strrpos($path, '/');
if ($length === false){ return false; }
$path = substr($path, 0, $length);
}

that should do it.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация