Results 1 to 5 of 5

Thread: Array Help

  1. #1
    Join Date
    Dec 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Array Help

    Hi all,

    I was going through some php tutorials and on the topic of arrays...

    To create an array you simply use the following syntax:
    $myArray = array("value", "value", "value);
    OR
    $myArray2 = array("value", array("value");

    So my question is: is the second one a two dimensional array?
    because you could reff. myArray2 with $myArray2[0][0];

    If yes... How could you set up the array structure to contain for example, category names and data within a category name...but have several different listings for a given category?

    Thanks.
    _______________________________________________
    welcome to best contact lens coupons

  2. #2
    Join Date
    Jul 2008
    Posts
    199
    Thanks
    6
    Thanked 58 Times in 57 Posts

    Default

    PHP Code:
    $var = array(
      
    'client' => array(
        
    'js',
        
    'css'
      
    ),
      
    'server' => array(
        
    'php',
        
    'jsp'
      
    )
    );
    //$var['server'][0] = PHP
    //$var['client'][1] = CSS 

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    PHP doesn't really have support for multidimensional arrays. It just uses arrays of arrays, which is what that example is (once the missing bracket is added) — an array with an array as one of its elements.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    Quote Originally Posted by Twey View Post
    PHP doesn't really have support for multidimensional arrays. It just uses arrays of arrays, which is what that example is (once the missing bracket is added) — an array with an array as one of its elements.
    I thought that is what multidimensional arrays were.
    To choose the lesser of two evils is still to choose evil. My personal site

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    No — some languages, such as Visual Basic and Haskell, have support for actual multidimensional arrays: a single array which takes as its key multiple values (or a tuple, in the case of Haskell). In homogenous arrays this is a rather cosmetic difference, but PHP arrays are heterogenous: they can contain different types, including mixing scalar values and other arrays, so it becomes rather important.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •