note 36483 added to function.list

From: Date: Sat, 11 Oct 2003 08:53:39 +0000
Subject: note 36483 added to function.list
Groups: php.notes 
Request: Send a blank email to php-notes+get-58228@lists.php.net to get a copy of this message
The documentation says that list() only works on numerical arrays, but it would be more accurate to say that it only works on array elements with numeric indices. At least I found this to be true with PHP 4.3.2 and 4.3.3 on Win32 and Linux. For example: <?php $people = array( 0 => "bob", 1 => "mary", "boy" => "jim", "girl" => "jane", 3 => "ted", 4 => "louise", "10" => "bill", "20" => "susie" ); list($one, $two, $three, $four, $five, $six, $seven, $eight) = $people; echo "<p>$one</p>"; echo "<p>$two</p>"; echo "<p>$three</p>"; echo "<p>$four</p>"; echo "<p>$five</p>"; echo "<p>$six</p>"; echo "<p>$seven</p>"; echo "<p>$eight</p>"; ?> Output is: bob mary ted louise So what list() actually does is to skip over any elements with non-numeric keys. I'm not sure whether this counts as a bug, an undocumented feature, or something that should be obvious, but it wasn't apparent to me until I stumbled across it by accident, so perhaps someone might find it useful. ---- Manual Page -- http://www.php.net/manual/en/function.list.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+36483 Delete -- http://master.php.net/manage/user-notes.php?action=delete+36483&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+36483&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#58228) next »