[thelist] functions in PHP and arguments (was: PHP string tip...)
Joe Crawford
jcrawford at avencom.com
Fri Aug 31 17:24:17 CDT 2001
Hi john --
You wrote:
<many snips>
> function make_p($string, $class=""){
> if (isset($class)){
> $p = "<p class = \"$class\">"}
> else{
> $p = "<p>";
> }
> $string = str_replace( chr(13) , "</p>$p" , $string );
> $string = $p. $string. "</p>\n";
> return $string;
> }
> </tip>
So *this* is the way to make arguments optional in PHP? This is
something that has bothered me for a while - how to make a function with
optional arguments.
A simple example would be my tr() function:
Now I have two functions:
function tr() { echo "<TR VALIGN=\"top\">\n"; };
and
function tr_color($c) { echo "<TR VALIGN=\"top\" bgcolor=\"$c\">\n"; };
So could I combine these somehow by making $c an optional argument?
function tr($c="") {
echo "<TR VALIGN=\"top\"";
if(isset($c))echo " bgcolor=\"$c\"";
echo ">\n";
};
Or is there a better way?
And how would I make a function with an arbitrary number of arguments?
like in JavaScript where you can access a functioname.arguments[] array.
Any help appreciated!
Joe
--
................... Joe Crawford \\ Web Design & Development
..... mailto:jcrawford at avencom.com \\ http://www.avencom.com
.... San Diego \\ CA \\ USA \\ AVENCOM: Set Your Sites Higher
More information about the thelist
mailing list