user defined functions with optional arguments?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Exyle

    user defined functions with optional arguments?

    I have a function that has two arguents, however depending on the value
    of the first argument, the second one may or may not be needed. If I
    only input the first argument when calling the function, PHP returns a
    warning. many built in php functions have optional arguments, is there a
    way to make arguments in user defined functions optional as well?

    Thanks.
  • Andy Hassall

    #2
    Re: user defined functions with optional arguments?

    On Wed, 17 Aug 2005 14:27:45 -0700, Exyle <usenet.qwest@r eg.exyled.net> wrote:
    [color=blue]
    >is there a way to make arguments in user defined functions optional[/color]



    --
    Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
    <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

    Comment

    • Joachim Weiß

      #3
      Re: user defined functions with optional arguments?

      Exyle schrieb:[color=blue]
      > I have a function that has two arguents, however depending on the value
      > of the first argument, the second one may or may not be needed. If I
      > only input the first argument when calling the function, PHP returns a
      > warning. many built in php functions have optional arguments, is there a
      > way to make arguments in user defined functions optional as well?
      >
      > Thanks.[/color]
      You have to give the second argument a default value

      function foo($arg1,$arg2 =NULL)

      then the function can be called without $arg2

      hih

      Jo

      Comment

      Working...