note 103311 added to function.list

From: Date: Wed, 06 Apr 2011 19:49:40 +0000
Subject: note 103311 added to function.list
Groups: php.notes 
Request: Send a blank email to php-notes+get-178571@lists.php.net to get a copy of this message
If your array is shorter than the number of arguments in list(), you will get an "undefined index" notice. You can solve it by making sure the array is long enough: <?php $array = Array( "one", "two" ); # This will give a Notice: undefined index [2]: list( $one, $two, $three ) = $array; # This won't: list( $one, $two, $three ) = $array + Array( null, null, null ); # If you know count($array) will be at least 1, you could skip the first index: list( $one, $two, $three ) = $array + Array( 1 => null, null ); # You could of course also use other default values: list( $one, $two, $three ) = $array + Array( "one", "two", "three" ); ?> ---- Server IP: 69.147.83.197 Probable Submitter: 145.53.45.17 ---- Manual Page -- http://www.php.net/manual/en/function.list.php Edit -- https://master.php.net/note/edit/103311 Del: integrated -- https://master.php.net/note/delete/103311/integrated Del: useless -- https://master.php.net/note/delete/103311/useless Del: bad code -- https://master.php.net/note/delete/103311/bad+code Del: spam -- https://master.php.net/note/delete/103311/spam Del: non-english -- https://master.php.net/note/delete/103311/non-english Del: in docs -- https://master.php.net/note/delete/103311/in+docs Del: other reasons-- https://master.php.net/note/delete/103311 Reject -- https://master.php.net/note/reject/103311 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#178571) next »