我有以下数组
array (
[customer_name] =>{customer1,customer2}
[phone] => {123456,123456}
[email] => {test@example.com,test2@example.com}
[project] => {"Project A","Project B"}
[property] => {A1,A2}
[amount] => {100.00,2000.00}
)
我想基于键拆分数组并分配给不同的变量。例如
$customer_name=array(customer1,customer2)
$phone=array(123456,123456)
// and so on
请帮忙。提前谢谢。
答案 0 :(得分:4)
您可以使用foreach来执行此操作并在循环内重新分配变量:
foreach($array as $key => $values) {
$values = str_replace(array('{', '}'), '', $values);
${$key} = explode(',', $values);
}