New to PHP, but totally confused.....

Discussion in 'PHP' started by Kulpreet, May 13, 2009.

  1. #1
    Hi there, I am totally new to PHP or honestly speaking new to programming.

    I have read PHP online and got some idea about its functions and uses...

    Now what i am really not able to understand is how and when to put different brackets and operators like- (), [], {}, '', "", <>.

    I read strings and think that some of the functions of these brackets are there, but still i am totally confused as when to use each of these brackets or braces.

    Someone please reply me....

    Regards
     
    Kulpreet, May 13, 2009 IP
  2. HomeComputerGames

    HomeComputerGames Peon

    Messages:
    871
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    That is a rather broad question.
    Perhaps you can download some simple script and play with it. Often just jumping in and doing is the best way to go. After awhile you will know how and when to use your "brackets" correctly.
     
    HomeComputerGames, May 13, 2009 IP
  3. creativeGenius

    creativeGenius Well-Known Member

    Messages:
    273
    Likes Received:
    5
    Best Answers:
    1
    Trophy Points:
    120
    #3
    hmm, i agree with the poster above, it's like asking how many stars are there (well it exaggerated lol) but the best way to learn is by trying and trying and trying... good luck
     
    creativeGenius, May 13, 2009 IP
  4. AdscendJeremy

    AdscendJeremy Peon

    Messages:
    63
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Brackets are used in arrays.
    Parenthesis is used to separate logic, such as... if (($1 > 1) AND ($b < 2)){
    Curly brackets are used for code blocks for "if" statements and functions
    Single quotes are for literal strings.
    Double quotes get interpreted, so you can put variables within double quotes. And characters such as \n (a new line)

    Hope this helps ;)
    Google "tizag PHP" - they have good basic tutorials.
     
    AdscendJeremy, May 13, 2009 IP
  5. Gordaen

    Gordaen Peon

    Messages:
    277
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #5
    And the confusing part is that most of those can be used for more than one thing. Early on, you'll most commonly see parentheses with functions, conditions, and grouping. Hopefully you'll make the progression toward using object oriented program when appropriate, in which case you'll see parentheses there too.

    Brackets are most commonly used with arrays, e.g., myArray[] or myArray['keyName'].

    Braces have a few purposes; they can be used to signify a block of code, like this:

    <?php
    if (true)
    {
        // This stuff is executed
        echo "This is printed.\n";
        echo "This would NOT be printed if you didn't use braces, but it is part of the group since there are braces, so it is printed also.";
    }
    ?>
    PHP:
    Braces can also be used for making variables easier to read, especially when doing some dynamic stuff (e.g., "${$myVar}") or printing (e.g., 'echo "I like {$favoriteColor}";' or 'echo "I like {$myFavorites->color}";'). There are some more uses for them, but those will come later.

    Single quotes and double quotes are mostly interchangeable, though variables in double quotes are processed where they're taken literally in single quotes. You might also want to read about heredoc.

    Besides the opening and closing tags, the less-than and greater-than symbols are mostly for comparison.

    That's a fairly generic answer to a very broad question, but hopefully it points you in the right direction.
     
    Gordaen, May 13, 2009 IP
  6. buldozerceto

    buldozerceto Active Member

    Messages:
    1,137
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    88
    #6
    The best way is to start with PHP for dummies book. It will help you a lot.
     
    buldozerceto, May 13, 2009 IP
  7. irfan saleem

    irfan saleem Active Member

    Messages:
    101
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    66
    #7
    irfan saleem, May 14, 2009 IP
  8. Syndrom

    Syndrom Peon

    Messages:
    89
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Syndrom, May 14, 2009 IP
  9. -[z]-

    -[z]- Active Member

    Messages:
    51
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #9
    My advice to you is to get a php script and tear it apart and play with it and see what happens when you change something... Trial and error is the best way.
     
    -[z]-, May 14, 2009 IP