SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    will code HTML for food Michel V's Avatar
    Join Date
    Sep 2000
    Location
    Corsica
    Posts
    552
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Functions with optional parameters

    (weird, it seemed to me that I already posted this thread, but there must have been an error)


    I've figured out how to make functions in PHP (of course), but how do I make functions that have optional parameters ?
    (The docs are a bit unclear about that... )
    [blogger: zengun] [blogware contributor: wordpress]

  2. #2
    Grumpy Mole Man Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,066
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can set default parameters for a function like this:
    PHP Code:
    function person($name='bob'$age='23')
    {
        
    // Code

    Now if you call person() the default values will be used, call person('james') and the name will be 'james' while the age will use the default etc. You can extend this to optional parameters by setting the default for a paratmer to false.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •