array_column这个函数应该能满足你的需求
$records = array(
array(
'id' => 2135,
'first_name' => 'John',
'last_name' => 'Doe',
),
array(
'id' => 3245,
'first_name' => 'Sally',
'last_name' => 'Smith',
),
array(
'id' => 5342,
'first_name' => 'Jane',
'last_name' => 'Jones',
),
array(
'id' => 5623,
'first_name' => 'Peter',
'last_name' => 'Doe',
)
);
$first_names = array_column($records, 'first_name');
var_dump($first_names);
会输出
Array
(
[0] => John
[1] => Sally
[2] => Jane
[3] => Peter
)
$arr=array(
'0'=>array(
'a'=>2,
'b'=>'fd',
'c'=>'fgd',
'd'=>'hg',
),
'1'=>array(
'e'=>2,
'b'=>'fd',
'f'=>'fgd',
),
'2'=>array(
'a'=>2,
'c'=>'fd',
'e'=>'fgd',
'b'=>'hg',
),
'3'=>array(
'c'=>2,
'd'=>'fd',
'e'=>'fgd',
'f'=>'hg',
),
);
foreach($arr as $k=>$v){
foreach($v as $key=>$val){
$arr2[$key]=$val;
}
}
$arr = array(
0 => array(
0 => array(
'id' => 5,
'name' => 'aaa',
'times' => 5
),
1 => array(
'id' => 5,
'name' => 'aaa',
'times' => 5
),
),
1 => array(
0 => array(
'id' => 5,
'name' => 'aaa',
'times' => 5
),
1 => array(
'id' => 5,
'name' => 'aaa',
'times' => 5
),
),
);
$arr2 = array();
foreach ($arr as $k => $v) {
foreach ($v as $m => $n) {
$arr2[0][] = $n;
}
}
echo "";
print_r($arr2);
?>