Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PHP二维数组转一位数组
<?php
//一个很大的二维数组
$arr = array(
0 => array(
'id'=>11,
'name'=>'name1'
),
1 => array(
'id'=>22,
'name'=>'name2'
),
2 => array(
'id'=>33,
'name'=>'name3'
)
);
//如何以最高的效率实现将上面的二维数组转为一位数组
array(
0 => 11,
1 => 22,
2 => 33
)
@DingK-R

This comment has been minimized.

Copy link

commented May 24, 2014

$final = array();

 foreach ($arr as $key => $val) {
     $final[] = $val['id'];
 }
 var_dump($final);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.