是否有一个可以轻松更改此数组的php函数(或过程):
Array(
['first_name']=>Array(
[0]=>'James'
[1]=>'Brian')
['middle_name']=>Array(
[0]=>'Green'
[1]=>'Chip')
['last_name']=>Array(
[0]=>'McIntosh'
[1]=>'Simpson')
)
进入这个数组?
Array(
[0]=>Array(
['first_name']=>'James'
['middle_name']=>'Green'
['last_name']=>'McIntosh')
[1]=>Array(
['first_name']=>'Brian'
['middle_name']=>'Chip'
['last_name']=>'Simpson)'
)
答案 0 :(得分:1)
$arr = array(array('James', 'Brian'),array('Green', 'Chip'),array('McIntosh', 'Simpson'));
function combinearrays($arr){
$subarr1 = array();
$subarr2 = array();
$finalarray = array();
for($i = 0; $i < count($arr); $i++){
$subarr1[] = $arr[$i][0];
$subarr2[] = $arr[$i][1];
}
$finalarr[] = $subarr1;
$finalarr[] = $subarr2;
var_dump($finalarr);
}
combinearrays($arr);