Today's Question:  What's your opinion about Alibaba mooncake incident?        GIVE A SHOUT

Technical Article => Web =>  PHP

Optional arguments in PHP function

  Pi Ke      2011-03-28 12:35:20      2,178    0    0

In PHP, we can define our own functions which can accept optional number of arguments. In this kind of functions, the optional argument should be set with default value.
Fox example, the next code example will illustrate this:
<?php
function func($name,$type=NULL)
{
echo "$name $type";
}
func("Hello");
echo "<br />";
func("Hello","world");
echo "<br />";
?>

Here $type is an optional argument. It must be set with a default value either NULL or some other value. 
Quite simple.Right! In other programming languages, we can achieve similar effects. This is very convenient if we sometimes want to call the same function with different number of arguments.
Also, in PHP API, there are some supplemental functions such as func_num_args(),func_get_arg() and func_num_args() which are to process the arguments passed by the user. This may also help you.

PHP OPTIONAL ARGUMENTS USER DEFINED FUNC

  SAVE AS PDF   MARK AS READ   MARK AS IMPORTANT

  RELATED


  0 COMMENT


No comment for this article.


  WRITE ARTICLE

Apple Pencil? No. IKEA Pencil!

By sonic0002
While the whole world raves about the recent Apple products and of course the advancements in the digital world, IKEA Singapore shows how traditional pen and paper still hold on to an old world charm. On its Facebook page, IKEA Singapore put up this post: Obviously this is a post laughes at the Appl