Q:

How to combine values of duplicate keys in a single array?

I've an array with duplicate keys but each key having a different value. What should I do to remove the duplicate keys and assign there values to the one unique key ?
This is the array 
"{"body_type":"liver","email":"sohaibahmed293@gmail.com","gender":{},"birth_date":"2010-01-01","symptoms":[{"Where do you hold the weight ?":"Protuding Belly"},{"How much weight do you want to lose?":"Need to lose 26-39 pounds"},{"Symptoms part 1":"Cravings"},{"Symptoms part 1":"Sleeping Problems"},{"Symptoms part 2":"Urinary Frequency"},{"Symptoms part 2":"Absent Minded"},{"Symptoms part 3":"Slow Metabolism"},{"Symptoms part 3":"Sleeping Problems"}]}"

Basically I'm getting this array dynamically. 
Thanks

A:

As per my understanding you are expecting something like below
$arr = json_decode('{"body_type":"liver","email":"sohaibahmed293@gmail.com","gender":{},"birth_date":"2010-01-01","symptoms":[{"Where do you hold the weight ?":"Protuding Belly"},{"How much weight do you want to lose?":"Need to lose 26-39 pounds"},{"Symptoms part 1":"Cravings"},{"Symptoms part 1":"Sleeping Problems"},{"Symptoms part 2":"Urinary Frequency"},{"Symptoms part 2":"Absent Minded"},{"Symptoms part 3":"Slow Metabolism"},{"Symptoms part 3":"Sleeping Problems"}]}', true);
$symptoms = [];
foreach ($arr['symptoms'] as $symptom)
{
    $symptoms[array_key_first($symptom)][] = reset($symptom);
}
$arr['symptoms'] = $symptoms;

print_r($arr);

Expected Output
Array
(
    [body_type] => liver
    [email] => sohaibahmed293@gmail.com
    [gender] => Array
        (
        )

    [birth_date] => 2010-01-01
    [symptoms] => Array
        (
            [Where do you hold the weight ?] => Array
                (
                    [0] => Protuding Belly
                )

            [How much weight do you want to lose?] => Array
                (
                    [0] => Need to lose 26-39 pounds
                )

            [Symptoms part 1] => Array
                (
                    [0] => Cravings
                    [1] => Sleeping Problems
                )

            [Symptoms part 2] => Array
                (
                    [0] => Urinary Frequency
                    [1] => Absent Minded
                )

            [Symptoms part 3] => Array
                (
                    [0] => Slow Metabolism
                    [1] => Sleeping Problems
                )

        )

)

