Reply to Last element of array ?

Your name:

Reply:


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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация