RE: alpha/beta/gamma TO $var['alpha']['beta'] = 'gamma'

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

 



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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux