SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot ameerulislam's Avatar
    Join Date
    Jul 2011
    Posts
    127
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    To understand how php.net works

    ok on this site, http://php.net/manual/en/function.basename.php

    I found in description
    string basename ( string $path [, string $suffix ] )

    In example

    PHP Code:
    <?php
    echo "1) ".basename("/etc/sudoers.d"".d").PHP_EOL;
    echo 
    "2) ".basename("/etc/passwd").PHP_EOL;
    echo 
    "3) ".basename("/etc/").PHP_EOL;
    echo 
    "4) ".basename(".").PHP_EOL;
    echo 
    "5) ".basename("/");
    ?>
    my question is (I hope not a silly one) why in the description the the square brackets started before the comma I expect it to be
    string basename ( string $path, [string $suffix ] )

    and not
    string basename ( string $path [, string $suffix ] )

    I find php.net not user friendly for newbies.

  2. #2
    SitePoint Addict
    Join Date
    Apr 2011
    Posts
    266
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Because the comma is needed only if it is added the other argument (in square brackets), otherwise no need to add comma.
    So, the comma comes with that argument, which is optional.
    Free: Web Programming Courses HTML, CSS, Flash
    Web Programming: AJAX Course and PHP-MySQL Course video Lessons
    Good JavaScript and jQuery course for beginners

  3. #3
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)
    It's pretty standard syntax. Anything inside [] is an optional component, but that component must be taken as a whole.

    function1(string $imrequired[,string $imnot[,string $...],int $anumber])

    Should be read as: "Needs 1 string. May have a second string, followed by 0 or more strings, and then a number."
    The function may have:
    1 parameter (string imrequired) function1("Haha")
    3 parameters (string imrequired, string imnot, and int anumber) function1("Haha","Nope",3)
    4+ paramters (string imrequired, string imnot, 1 or more string $..., and int anumber) function1("AString","BString","CString",9000)

    If the comma were outside the [], it would be required, and thus the syntax would be function1("Haha",) , which makes no sense.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  4. #4
    SitePoint Zealot ameerulislam's Avatar
    Join Date
    Jul 2011
    Posts
    127
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thank You guys. All clear now!


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
  •