note 50008 deleted from function.func-get-args by danbrown

From: Date: Fri, 15 Jul 2011 17:47:34 +0000
Subject: note 50008 deleted from function.func-get-args by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-181582@lists.php.net to get a copy of this message
Note Submitter: robert at defore dot st ---- <?php # Another attempt at named args (perl-inspired): # list_to_assoc('key', 'value', 'key', 'value', ...) => # pairs[] function list_to_assoc() { $list = func_get_args(); $assoc = array(); while ($list and count($list) > 1) { $assoc[array_shift($list)] = array_shift($list); } if ($list) { $assoc[] = $list[0]; } return $assoc; } # Usage: function example($required) { $args = func_get_args(); array_shift($args); # drop 'required' $rest = list_to_assoc($args); echo "$required\n" . $rest['comment']; } ?> example("This is required...", 'comment', 'this is not.'); # this is like 'comment' => 'this is not'

« previous php.notes (#181582) next »