这个怎么样?我不知道你想怎么处理重复的钥匙,所以我把选择权留给你了。只要替换一下
; // Do something here on duplicate key
$info = Array(
'name' => 'Someone',
'email' => 'someone@none.local',
'billing' => Array(
'address_1' => '1234 Somewhere',
'address_2' => NULL,
'city' => 'Somewhere',
'state' => 'ST',
'country' => 'CO',
'postal_code' => '12345'
),
'shipping' => Array(
'address_1' => '1234 Somewhere',
'address_2' => NULL,
'city' => 'Somewhere',
'state' => 'ST',
'country' => 'CO',
'postal_code' => '12345'
)
);
function explodeArray($array, &$data, $prefix = "") {
foreach ($array as $key => $value) {
if (is_array($value)) {
explodeArray($value, $data, $prefix . $key . "_");
} else {
if (!array_key_exists($prefix . $key, $data)) {
$data[$prefix . $key] = $value;
} else {
; // Do something here on duplicate key
}
}
}
}
$result = array();
explodeArray($info, $result);
print_r($result);