Re: get last directory of a full path? (parent directory)

From: Date: Sun, 21 Jan 2001 00:16:35 +0000
Subject: Re: get last directory of a full path? (parent directory)
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-35859@lists.php.net to get a copy of this message
> $i = 1; > foreach ($dirs as $value) { > if ($i == ($numberofelements-1)) $lastdir = $value; > if ($i == $numberofelements) $file = $value; > $i++; > } I don't think the foreach is necessary - Why can't you just say: $lastdir = $dirs[$numberofelements-1]; $file = $dirs[$numberofelements]; That way you're not traversing the entire array, you're just getting what you need, more efficient. Now if only you could work with files the same way you can with arrays...

« previous php.general (#35859) next »