SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru
    Join Date
    Nov 2008
    Posts
    848
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What quotes to use

    When declaring arrays is double quotes better than single quotes?

    return array("slug"=>$parentslug,"title"=>$parenttitle);

    return array('slug'=>$parentslug,'title'=>$parenttitle);

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Most of the time it doesn't matter, but double quoted strings support more complex syntax inside of them. So, the general rule of thumb is, use single quoted strings unless you have a reason to use the double quoted syntax. Whether or not you're using them in relation to arrays is irrelevant.

    http://www.php.net/manual/en/language.types.string.php

  3. #3
    SitePoint Wizard frank1's Avatar
    Join Date
    Oct 2005
    Posts
    1,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by drtanz View Post
    When declaring arrays is double quotes better than single quotes?

    return array("slug"=>$parentslug,"title"=>$parenttitle);

    return array('slug'=>$parentslug,'title'=>$parenttitle);
    only thing you cannot do is this
    return array('slug'=>'$parentslug','title'=>$parenttitle);
    but can do this
    return array('slug'=>"$parentslug",'title'=>$parenttitle);
    others all fine

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by frank1 View Post
    only thing you cannot do is this
    return array('slug'=>'$parentslug','title'=>$parenttitle);
    Yes you can. $array['slug'] will contain '$parentslug'

  5. #5
    SitePoint Wizard frank1's Avatar
    Join Date
    Oct 2005
    Posts
    1,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    Yes you can. $array['slug'] will contain '$parentslug'
    yup,one thing you should not forget syntax errors are easier to detect but logical errors like that will keep for busy for nothing.....
    so keep it for the day ...when you feel bored....
    (long investigation ...why is my array not working...)


    no offence....


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
  •