0

print_r($unique_id);

Array
(
    [0] => Array
        (
            [LeadEmailDetail] => Array
                (
                    [id] => 97
                    [email] => [email protected]
                )
        )

    [1] => Array
        (
            [LeadEmailDetail] => Array
                (
                    [id] => 93
                    [email] => [email protected]
                )
        )

    [2] => Array
        (
            [LeadEmailDetail] => Array
                (
                    [id] => 94
                    [email] => [email protected]
                )
        )

)

But i want like that

Array
(
    [0] => Array
        (
            [id] => 97
            [email] => [email protected]
        )

    [1] => Array
        (
            [id] => 93
            [email] => [email protected]
        )

    [2] => Array
        (
            [id] => 94
            [email] => [email protected]
        )

)

5 Answers 5

1

Try this:

array_map('array_shift', $unique_id);
Sign up to request clarification or add additional context in comments.

Comments

1

try this

foreach($unique_id as $k => $v)
{
    $array[] = array_shift($v);
}

Comments

1

Simple loop does a job for you:

foreach ($array as &$v) {
    $v = current($v);
}
unset($v);

demo

p.s. doesn't create another array (memory leak) like other examples.

Comments

1

print_r( array_column( $unique_id, 'LeadEmailDetail' ) );

Requires PHP >= 5.5.0

1 Comment

A second this answer, but it should be noted that this requires php>=5.5.
0

Who build the $unique_id array? I would recommend to build it in the form you like

To solve your question ... out of the box quick and dirty

<?php
    $new = array();
    foreach($unique_id as $arr) {
       foreach ($arr['LeadEmailDetail'] as $a) {
         $new[] = $a;
       }
    }
    print_r($new);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.