2

I want to change last child of array (122) with second child of array (0). You can see with samples. Please help me.

Current version:

Array
(
    [0] => Array
        (
            [122] => Array
                (
                    [PROGRAM_ID] => 181
                    [VENUE_ID] => 2
                    [AUDIT_ID] => 96
                )

        )

)

I want this:

Array
(
    [122] => Array
        (
            [PROGRAM_ID] => 181
            [VENUE_ID] => 2
            [AUDIT_ID] => 96
        )

)
2
  • $myarray = $myarray[0]; Commented May 30, 2013 at 11:46
  • It works for only one child. I have hundreds of array values. Commented May 30, 2013 at 12:06

2 Answers 2

2

This works fine $array = reset($array); for the first child and $array = end($array); for the last.

Sign up to request clarification or add additional context in comments.

Comments

0

I suppose you're looking for something like this....

https://stackoverflow.com/a/2408971/1172872

Like this:

$result = array();

foreach($array as $inner) {
    $result[key($inner)] = current($inner);        
}

The $result array would now look like this:

Array
(
    [122] => Array
    (
        [PROGRAM_ID] => 181
        [VENUE_ID] => 2
        [AUDIT_ID] => 96
    )
)

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.