RE: [PHP] alpha/beta/gamma TO $var['alpha']['beta'] = 'gamma'
| From: | Ford, Mike | Date: | Mon, 08 Jun 2009 12:27:06 +0000 |
| Subject: | RE: [PHP] alpha/beta/gamma TO $var['alpha']['beta'] = 'gamma' | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-293723@lists.php.net to get a copy of this message | ||
On , nitsan@binnun.co.il 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@leedsmet.ac.uk
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