1

I have the following array being returned

Array
    (
        [0] => Array
            (
                [uid] => 616941445
            )

        [1] => Array
            (
                [uid] => 1354124203
            )

    )

However I want just a single layered array, so i would like something like this.

Array
(     
[0] => 616941445
[1] => 1354124203
)
0

4 Answers 4

4
foreach ($arr as $key => $val) {
  $arr[$key] = $val['uid'];
}
Sign up to request clarification or add additional context in comments.

2 Comments

Or $arr[$key] = $val['uid'] which is the same…
i wanted to not have to loop through each result and thought there maybe an array function... I guess not though. Thanks
0
<?php
$multi_arr = array(
    array(
        'uid' => 616941445
    ),
    array(
        'uid' => 1354124203
    ),
);

$single_arr = array();
foreach($multi_arr as $arr){
    foreach($arr as $val) $single_arr[] = $val;
}
?>

Comments

0

As always, when you need to change two level array into one level without preserve keys:

$your2DArray = array(/* .. */);
$flatArray = array_map('array_pop', $your2DArray);

And like you want to, no loops.

1 Comment

Actually, there are loops - they are just hidden inside your call to array_map.
0
foreach($arr as $key=>$val) {
    $single_arr[] = $arr[$key]['uid'];
}

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.