Results 1 to 5 of 5

Thread: Multidimensional Array

  1. #1

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Multidimensional Array

    I have an array, I want to be able to access the array like this...

    Code:
    $book['author'][0]
    But it wont let me access the array, any reason why? I have to be able to access using its name, author, title etc.

    Code:
    (
        [0] => Array
            (
                [0] => author
                [1] => 
                [2] => 
                [3] => 1
            )
    
        [1] => Array
            (
                [0] => year_of_publication
                [1] => 
                [2] => 
                [3] => 1
            )
    
        [2] => Array
            (
                [0] => title
                [1] => <em>
                [2] => </em>
                [3] => 1
            )
    
        [3] => Array
            (
                [0] => edition
                [1] => 
                [2] => 
                [3] => 
            )
    
        [4] => Array
            (
                [0] => publisher
                [1] => 
                [2] => 
                [3] => 1
            )
    
    )

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Multidimensional Array

    The array is an indexed array and therefore must be accessed with indexes i.e: 0,1,2,3 . It is difficult from what you have shown above where the data has come from. Is it a regular expression?
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Re: Multidimensional Array

    I physically make the array further up in the script, here it is...

    Code:
    // field, prefix, suffix, required
    $book = array( 
    	array('author', '', '', true),
    	array('year_of_publication', '', '', true),
    	array('title', '<em>', '</em>', true),
    	array('edition', '', '', false),
    	array('publisher', '', '', true)
    );

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Multidimensional Array

    Author is a key. So use the => operator to specify this in your top level array:
    Code:
    $book = array (
        'author' => array('','',true) ...
    ...
    ...
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Re: Multidimensional Array

    Cheers Adam[0]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width