user1690835 user1690835 - 1 year ago 96
PHP Question

Split associative array based on keys

I have the following array

array (
[customer_name] =>{customer1,customer2}
[phone] => {123456,123456}
[email] => {,}
[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

// and so on

Please help. Thanks in advance.

Answer Source

You could use foreach to do that and reassign variables inside the loop:

foreach($array as $key => $values) {
    $values = str_replace(array('{', '}'), '', $values);
    ${$key} = explode(',', $values);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download