0

I've got an associative array with (it seems like) a dynamic integer. The array:

array(4) {
    ["attendees"]=> array(1) {
        [4]=> array(1) {
            [0]=> array(9) {
                ["attendee_firstname"]  => string(6) "Privat"
                ["attendee_secondname"] => string(6) "Privat"
                ["attendee_city"]       => string(4) "Test"
                ["attendee_sex"]        => string(3) "Man"
                ["attendee_dob"]        => string(10) "1980-01-15"
                ["attendee_email"]      => string(12) "[email protected]"
                ["attendee_phone"]      => string(10) "0606060606"
                ["attendee_speed"]      => string(12) "testt - seln"
                ["attendee_shirtsize"]  => string(2) "XS"
            }
        }
    } 
    ["registration"]=> array(9) { 
        ["user_name"]   => string(5) "admin"
        ["user_email"]  => string(0) ""
        ["dbem_address"]=> string(4) "test"
        ["dbem_city"]   => string(4) "test"
        ["dbem_state"]  => string(4) "test"
        ["dbem_zip"]    => string(6) "8888ZZ"
        ["dbem_country"]=> string(2) "BD"
        ["dbem_phone"]  => string(0) ""
        ["dbem_fax"]    => string(0) "" 
    }
    ["booking"]=> array(1) {
        ["booking_comment"]=> string(0) "" 
    }
    ["gateway"]=> string(18) "idealcheckoutideal"
}

For example, if I want to get the attendee_firstname I use the following:

$data["attendees"][4][0]["attendee_firstname"]

The problem is that the 4 could be anything. (But I can't change the way this works either, sadly) Is there a way to set an unspecified index?

2 Answers 2

3

You can reset keys with array_values:

array_values($data["attendees"])[0][0]["attendee_firstname"]
Sign up to request clarification or add additional context in comments.

2 Comments

I don't actually understand his question, what is a `dynamic integer'?
@MehdiBounya It could be anything and could possibly change. It's a function that I cannot (not allowed to) change.
0

You can try this to have a 0-based index:

$data["attendees"] = array_values($data["attendees"]);

or this to iterate, no matter the keys:

foreach ($data["attendees"] as $idx => $value) {
    // do something with $value
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.