1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP array help

Discussion in 'PHP' started by myinnet, Feb 26, 2008.

  1. #1
    i have an array like:
    Array
    (
        [ResultSet] => Array
            (
                [Result] => Array
                    (
                        [0] => yahoo china
                        [1] => china airlines
                        [2] => china map
                        [3] => air china
                        [4] => china mobile tv phone
                        [5] => china news
                        [6] => china travel
                        [7] => china population
                        [8] => bank of china
                        [9] => china southern airlines
                    )
    
            )
    
    )
    Code (markup):
    I would like to get the length of the array, as you know, the length maybe 10, maybe 40. and i want to get the items from the array, such as
    $result[0], i know this is not right, but i do not know how to write. please help.
    thanks
     
    myinnet, Feb 26, 2008 IP
  2. able

    able Peon

    Messages:
    44
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    get the length with:

    $length = count($array['ResultSet']['Result']);

    Access with:

    $array['ResultSet']['Result'][0]
     
    able, Feb 26, 2008 IP
  3. myinnet

    myinnet Peon

    Messages:
    81
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    i should add some details to this one.
    $obj=Array
    (
    [ResultSet] => Array
    (
    [Result] => Array
    (
    [0] => yahoo china
    [1] => china airlines
    [2] => china map
    [3] => air china
    [4] => china mobile tv phone
    [5] => china news
    [6] => china travel
    [7] => china population
    [8] => bank of china
    [9] => china southern airlines
    )

    )

    )

    do i need to add $obj to somewhere?
     
    myinnet, Feb 26, 2008 IP
  4. able

    able Peon

    Messages:
    44
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Just change $array to $obj

    get the length with:

    $length = count($obj['ResultSet']['Result']);

    Access with:

    $obj['ResultSet']['Result'][0]
     
    able, Feb 26, 2008 IP
  5. myinnet

    myinnet Peon

    Messages:
    81
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    sorry, i got it working now. thanks for all your help.
     
    myinnet, Feb 26, 2008 IP