[英]Split associative array based on keys
I have the following array 我有以下数组
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}
)
I want to split the array based on keys and assign to different variables. 我想基于键拆分数组并分配给不同的变量。 For example
例如
$customer_name=array(customer1,customer2)
$phone=array(123456,123456)
// and so on
Please help. 请帮忙。 Thanks in advance.
提前致谢。
You could use foreach to do that and reassign variables inside the loop: 您可以使用foreach做到这一点并在循环内重新分配变量:
foreach($array as $key => $values) {
$values = str_replace(array('{', '}'), '', $values);
${$key} = explode(',', $values);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.