发出从数组中获取信息的问题

I'm trying to get info out of this information:

Array (
    [result] => success
    [totalresults] => 1
    [startnumber] => 0
    [numreturned] => 1 
    [tickets] => Array (
        [ticket] => Array (
            [0] => Array (
                [id] => 7
                [tid] => 782755
                [deptid] => 1
                [userid] => 39
                [name] => Mark Lønquist
                [email] => mark.loenquist@outlook.com
                [cc] => 
                [c] => 79rzVBeJ
                [date] => 2013-04-25 16:14:24
                [subject] => test
                [status] => Open
                [priority] => Medium
                [admin] => 
                [attachment] => 
                [lastreply] => 2013-04-25 16:14:24 
                [flag] => 0
                [service] => 
            )
        )
    )
)

The results are printed using:

print_r($results);

Usually, I've been able to do a simple:

$var = $results['something'];

To get it out, but it wont work with this :( Any help is appreciated.

After reformatting the array you pasted, it becomes clear that some elements are nested several levels deep. (It's a "multidimensional array"; see example #6 in the docs.) In those cases, you have to add additional brackets containing each successive key to reach the depth you want. For example, a sample from your $results array:

Array (
    [result] => success
    [totalresults] => 1
    ...
    [tickets] => Array (
        [ticket] => Array (
            [0] => Array (
                [id] => 7
                [tid] => 782755
                ...
            )
        )
    )
)

You simply need to do $results['totalresults'] to access "totalresults", but to get "tid" you would need to use $results['tickets']['ticket'][0]['tid'].


If you want to get "tid" from all of the tickets when there are multiple, you will have to iterate (loop) over the array of tickets. Probably something like this (untested, but should be close enough for you to figure out):

foreach ($results['tickets']['ticket'] as $ticket) {
    echo $ticket['tid'];
}

To see what the problem is with your print_r() you may add error_reporting(E_ALL); to the top of your code.

Note that if you want to retrieve the value for a key such as 'totalresults' then $results['totalresults'] would be sufficient.

However, if you want to get a key from one of the nested arrays such as email then you would have to use $results['result']['tickets']['ticket'][0]['email'].