如何在以下场景中操作数组?

时间:2014-03-18 04:38:22

标签: php arrays associative-array

我的数组名为$email_ids

Array
(
    [0] => Array
        (
            [user_email] => abc@gmail.com
        )

    [1] => Array
        (
            [user_email] => lmn@gmail.com
        )

    [2] => Array
        (
            [user_email] => pqr@gmail.com
        )

)

我想以followinf格式将其转换为数组:

Array
    (
[0] => abc@gmail.com
[1] => lmn@gmail.com
[2] => pqr@gmail.com

    )

我应该如何以最佳方式获得这个?

3 个答案:

答案 0 :(得分:2)

array_map(function($x){return $x['user_email'];}, $email_ids)

答案 1 :(得分:1)

使用简单的foreach

$newarr = array();
foreach($yourarray as $k=>$arr)
{
 $newarr[]=$arr['user_email'];
}

Demo

答案 2 :(得分:1)

试试这个

$temp = array();

foreach($arr as $val){
    $temp[] = $val['user_email'];
}

var_dump($temp);