I wrote that function in a couple of minutes, haven't dedicated much time to think of the efficiency of it, you are definitely right but I'm pretty much sure that for 10 segments URLs you won't feel the difference. If you want I can benchmark it. Thanks for the heads up. -- Nitsan On Mon, Jun 8, 2009 at 3:27 PM, Ford, Mike <M.Ford@xxxxxxxxxxxxxx> wrote: > On , nitsan@xxxxxxxxxxxx advised: > > > >> function nitsanush($v) > >> { > >> $a = explode("/", $v); > >> if (sizeof($a) > 2) > >> { > >> $b = $a; > >> unset($b[0]); > >> return array($a[0] => nitsanush(implode("/", $b))); } > >> else > >> { > >> return array($a[0] => $a[1]); > >> } > >> } > >> > >> // eof > >> > > That looks like severe overkill -- recursion *and* an implode/explode > per "directory"?? > > I'd write it something like this: > > function convert($pseudo_path) > { > $pseudo_dirs = explode('/', $pseudo_path); > $result = array_pop($pseudo_dirs); > for ($i=count($pseudo_dirs-1; $i>=0; --$i): > $result = array($pseudo_dirs[$i] => $result); > endfor; > > return $result; > } > > This is completely off the top of my head and untested, so no guarantees > provided ;) > > Cheers! > > Mike > > -- > Mike Ford, Electronic Information Developer, > C507, Leeds Metropolitan University, Civic Quarter Campus, > Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom > Email: m.ford@xxxxxxxxxxxxxx > Tel: +44 113 812 4730 > > > To view the terms under which this email is distributed, please go to > http://disclaimer.leedsmet.ac.uk/email.htm > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >