Re: List() help

From: Date: Mon, 10 May 2004 05:34:41 +0000
Subject: Re: List() help
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-185775@lists.php.net to get a copy of this message
On Sun, 2004-05-09 at 21:13, PHPDiscuss - PHP Newsgroups and mailing lists wrote: > I'm using list like > list($a,$b,$c,$d) = $MyArray > MyArray holds more than three items, 0-4 more, > my problem is that $d only gets one and I lose the others if more tha one > extra. I know I can just add more $e,f,g,h,i but how do I get the extras > into an array? Try using array_shift[1] for the first few items instead of list: $a = array_shift($MyArray); $b = array_shift($MyArray); $c = array_shift($MyArray); $MyArray will have the leftovers, you can just assign it if you need a copy: $d = $MyArray; If you only want $d to be an array when there is more than one entry left do this instead: if (count($MyArray) == 1) { $d = array_shift($MyArray); } else { $d = $MyArray; } [1] http://www.php.net/array_shift -- Adam Bregenzer adam@bregenzer.net http://adam.bregenzer.net/

« previous php.general (#185775) next »