$id=
Array
(
[0] => 1
[1] => 2
[2] => 16
)
$oid=
Array
(
[0] => 1
[1] => 1
[2] => 2
)
I want to combine it into an array as follows:
$data =
Array
(
[0] =>
[id]=1
[oid]=1
[1] =>
[id]=2
[oid]=1
[2] =>
[id]=16
[oid]=2
)
Please help me
漂亮男人2017-06-29 10:10:34
$data = array();
for ($i = 0; $i < count($id); $i++) {
$data[$i] = array(
'id' => $id[$i],
'oid' => $oid[$i]
);
}
var_dump($data);
欧阳克2017-06-29 10:10:34
$data=[];
foreach($id as $key=>$va){
$data[]=[
'id'=>$va,
'oid'=>$oid[$key]
];
}
为情所困2017-06-29 10:10:34
Read more damn official documents, you don’t need to ask any master to help with these problems... (Hey, write it down casually, the $result below should be what you want...)
$result = array_map(function($item1, $item2) {
return ['id' => $item1, 'oid' => $item2];
}, $id, $oid);
迷茫2017-06-29 10:10:34
<?php
$id=[1,2,16];
$oid=[1,1,2];
array_work($id, function(&$v,$k)use ($oid){
$v=['id'=>$v,'oid'=>$oid[$k]];
});
print_r($id);
大家讲道理2017-06-29 10:10:34
$data = array();
foreach($id as $key =>$val){
$data[] = array(
'id' => $val,
'old' => $
);
}