Mailinglisten-Archive |
-----Ursprüngliche Nachricht-----
> von Matthias Otterbach
> Gesendet: Samstag, 19. Mai 2001 14:23
> An: php_(at)_phpcenter.de
> Betreff: Re: [php] array
> Probier das doch einfach so:
> $array = array(1,3,4);
> $next = $array[0];
> for($i = 0; $i < count($array); $i++) {
> $new_next = $array[$i + 1];
> $array[$i + 1] = $next;
> $next = $new_next;
> }
> $array[0] = 5;
Wenn man schon $i auf die größe des Arrays beschränkt, dann sollte man den
count($array); vorher in eine Var schreiben, weil ansonsten, verlängert sich
das Array immer um ein Element mehr und es kommt zu einer for-schleife ohne
Ende ;o)
$array = array(1,3,4);
$count = count($array);
$next = $array[0];
for($i=0;$i<$count;$i++) {
$new_next = $array[$i + 1];
$array[$i + 1] = $next;
$next = $new_next;
}
$array[0] = 5;
So sollte es stimmen!
Mfg
--
Tino Ehrich
[application designer]
eMail: tino.ehrich_(at)_dev-media.de
Handy: 0162 - 5474665
ICQ: 92712291
Erst wenn man alles verloren hat, hat man die Freiheit alles zu machen.
php::bar PHP Wiki - Listenarchive