SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Check if variable is set

    When I have a function, how do i check if the second variable is filled in?


    for example:
    Code PHP:
    function whatever($first, $second) {
     
    if([[[only first variable is filled in]]]) {
    something();
    }
     
    if([[[second variable is filled in]]]) {
    somethingelse();
    }
     
     
    }
     
    whatever(onlyone);
    whatever(thereisone, andtwo);


    do i use !(isset($second)) and (isset($second)) or do i use something else ??

  2. #2
    Fully Sweet Car noddy's Avatar
    Join Date
    Aug 2002
    Location
    Perth, Western Australia
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks

  4. #4
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    function test ($paramA$paramB null) {

        if (!
    is_null($paramB)) {
            print 
    '$paramB is not null';
        }


    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  5. #5
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    All defined parameters must be present unless a default value is set. In other words if you have myfunction( $paramA, $paramB ) both parameters must be stated when calling the function or a fatal error will be generated. If you have myfunction( $paramA, $paramB = "" ) then you only need to supply the function with the first value, the second will default to "".
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.


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
  •