我从表中获取了一个数组
arr1 = Array
(
[0] => Array
(
[option_value_id] => 30
[duration_id] => 1
[price_value] => 13
)
[1] => Array
(
[option_value_id] => 30
[duration_id] => 2
[price_value] => 14
)
[2] => Array
(
[option_value_id] => 30
[duration_id] =>3
[price_value] =>15
)
[4] => Array
(
[option_value_id] => 31
[duration_id] => 1
[price_value] => 16
)
[5] => Array
(
[option_value_id] => 31
[duration_id] => 2
[price_value] => 17
)
[6] => Array
(
[option_value_id] => 31
[duration_id] =>3
[price_value] => 18
)
我需要duration_id作为键,option_value_id作为duration_id数组中的键 我的结果数组应该看起来像这样
Array
(
[1] => Array
(
[30] => 13
[31] => 16
)
[2] => Array
(
[30] => 14
[31] => 17
)
[3] => Array
(
[30] => 15
[31] => 18
)
)
?>
答案 0 :(得分:7)
这应该可以解决问题:
$result = array();
foreach($arr1 as $val){
$result[$val['duration_id']][$val['option_value_id']] = $val['price_value'];
}