user1117742456
user1117742456

Reputation: 213

Getting Array Data

The following is a profile array printed using r_print:

Array
(
    [0] => Array
        (
            [Title] => Profile
            [Name] => Veritas
            [NKey] => Key_1
            [SKey] => Key_2
        )

    [1] => Array
        (
            [Title] => Access
            [Admin] => True
            [Banned] => False
            [Public] => True
        )

)

What I'm trying to do, is simply retrieve elements of that array.

IE,

$profile[] = ...; //GET_ARRAY
$user = $profile[0]['Name'];
$key_1 = $profile[0]['NKey'];
$key_2 = $profile[0]['SKey'];
$admin = $profile[1]['Admin'];

For some reason, the above code doesn't work, though logically it should work without a problem. What IS returned, is just the character 'A' if I target anything within the array.

Upvotes: 0

Views: 53

Answers (2)

user1117742456
user1117742456

Reputation: 213

Figured out what I was looking for, thought PHP automatically formated arrays (string data) passed from another page. I solved my issue using serialize() & unserialize().

Upvotes: 0

John Conde
John Conde

Reputation: 219814

You are adding another level to your array by assigning the array to $profile[]. The brackets turn $profile into an array and then adds that array to it causing the extra level.

$profile[] = ...; //GET_ARRAY

should just be

$profile = ...; //GET_ARRAY

Upvotes: 2

Related Questions