SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard
    Join Date
    Jan 2005
    Location
    blahblahblah
    Posts
    1,447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [array] what's wrong with this syntax (parse error)?

    PHP Code:
    $blah = array ("key_one" => "one""key_whatever" => "whatever""one_more_key" => "blah"123); 
    Also: do I have to use double quotes or can I use single quotes?

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Honestly? Not alot!
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Single or double quotes are fine.

    What exactly is the error you get.

    My test code
    PHP Code:
      $blah = array ("key_one" => "one""key_whatever" => "whatever""one_more_key" => "blah"123); 
      
    print_r($blah); 
    Results
    Code:
       Array (     [key_one] => one     [key_whatever] => whatever     [one_more_key] => blah     [0] => 1     [1] => 23 )
    No parse errors

  4. #4
    SitePoint Wizard
    Join Date
    Jan 2005
    Location
    blahblahblah
    Posts
    1,447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    weird... it's gone now.

    probably one of these stupid newbies errors...

  5. #5
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I use single quotes unless you need to use \n \r or \t to format the output, or a variable.

    Double quotes will have PHP interpret their contents to see if there are any variables contained. Single quotes elements will just be taken exactly as is.
    It can be slighly faster, and easier to read IMO to use single quotes when they are all you need.


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
  •