我有一个std类$ fee_str和另一个std类$ total_amount数组。我想同时插入两个数组以获得另一个std类对象。
Array
(
[0] => stdClass Object
(
[class] => 1
)
[1] => stdClass Object
(
[class] => 10
)
)
Array
(
[0] => stdClass Object
(
[fee_amount] => 8285
)
[1] => stdClass Object
(
[fee_amount] => 300
)
)
$fee_str=$this->fee_settings_model->load_fee_structure();
$i=0;
foreach ($fee_str as $key => $classes) {
$total_amount[$i]=$this->fee_settings_model->get_total_by_class($classes->class);
$i++;
}
$data=array_merge($fee_str,$total_amount);
echo "<pre>";
print_r($data);
exit;
我想得到这样的结果
Array
(
[0] => stdClass Object
(
[class] => 1
[fee_amount] => 8285
)
[1] => stdClass Object
(
[class] => 10
[fee_amount] => 300
)
)
答案 0 :(得分:0)
请找到内联文档进行解释,
function multiArrayCombine($array1, $array2)
{
$temp = array_map(null, $array1, $array2); // switch index wise data on either side
foreach ($temp as $key => &$value) { // & to make changes at address of variable
$value = json_decode(json_encode($value), true); // convert object to array
$value = array_merge(...$value); // removing initial index and merge internally
}
return json_decode(json_encode($temp)); // convert back to object form
}
$arr = multiArrayCombine($arr, $arr1);
print_r($arr);