note 71090 added to functions.arguments

From: Date: Sat, 11 Nov 2006 18:40:34 +0000
Subject: note 71090 added to functions.arguments
Groups: php.notes 
Request: Send a blank email to php-notes+get-119609@lists.php.net to get a copy of this message
It is easier to define a function with optional parameters by defining the function name with blank arguments and the calling for the arguments within the function itself: function foo_display () { list ( $name, $address, $phone ) = func_get_args (); if ( false == empty ( $name ) ): $arr_return[] = $name; endif; if ( false == empty ( $address ) ) : $arr_return[] = $address; endif; if ( false == empty ( $phone ) ): $arr_return[] = $phone; endif; return $arr_return; } By this design you can call the function with any number of arguments passed: $display = foo_display ( "john doe", "minnesota" ); foreach ( $display as $keys ) { print "value: $keys<br>"; } will output value: john doe value: minessota or: $display = foo_display (); foreach ( $display as $keys ) { print "value: $keys<br>"; } will output a blank line. and there will be no error upon calling the function. Just a question though, how can I pass an array into the argument list of a function call? Please advise, Thanks ---- Server IP: 66.163.161.117 Probable Submitter: 222.126.2.178 ---- Manual Page -- http://www.php.net/manual/en/functions.arguments.php Edit -- https://master.php.net/note/edit/71090 Del: integrated -- https://master.php.net/note/delete/71090/integrated Del: useless -- https://master.php.net/note/delete/71090/useless Del: bad code -- https://master.php.net/note/delete/71090/bad+code Del: spam -- https://master.php.net/note/delete/71090/spam Del: non-english -- https://master.php.net/note/delete/71090/non-english Del: in docs -- https://master.php.net/note/delete/71090/in+docs Del: other reasons-- https://master.php.net/note/delete/71090 Reject -- https://master.php.net/note/reject/71090 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#119609) next »