Posted by Schraalhans Keukenmeester on 10/18/05 05:13
I need the first, last and middle elements of a (single dimension) array
during a loop which may then add 0..n elements to it so I don't know how
many elements are in it the next run.
Right now I use:
[....]
$len = count($arr);
$var0 = $arr[0];
$var1 = $arr [$len];
$var2 = $arr [$len div 2];
[...]
but i get the idea there may be a faster/more elegant solution than
calculating its length each run.
I know there are languages that feature a tail() and mid() functions to
get the last element of an array. Can't find equivalents in PHP5. Are
there any ? (If the array has string indexes it becomes even more of a
hassle, doesn't it?)
Thx
Sh
Navigation:
[Reply to this message]
|