Anonymous Arrays

From: Date: Fri, 09 Mar 2001 16:06:05 +0000
Subject: Anonymous Arrays
Groups: php.general 
Request: Send a blank email to php-general+get-43160@lists.php.net to get a copy of this message
Does PHP4 have anything similar to perl's anonymous hash or array( $var = { 'some' => 'hash elements' } or $var = [ 'array', 'elements' ] ) The reason I ask is I am trying to find a way of passing a variable length list of named parameters to a function without having to use a specific order. i.e. function my_func is expecting any of the following optional parameters: fname, lname, city, state, zip I can do this with the following code: <?php function my_func ( $input ){ echo '<PRE>';print_r( $input );echo '</PRE>'; } $my_array = array( 'fname' => 'joe', 'lname'=>'coder', 'zip'=>'12345'); my_func( $my_array ); $my_array = array( 'city' => 'Brooklyn', 'state'=>'NY'); my_func( $my_array ); ?> To make it a little cleaner I would prefer to do something like: my_func( { 'fname' => 'joe' , 'lname'=>'coder' , 'zip'=>'12345' } ); an not pollute the code with one-time vars Thanks, Morgan

« previous php.general (#43160) next »