I have a result array from array\_merge and json encode and it look like below:

```
$c=[{"type":"textarea","label":"textarea","Element_Values":"cfgedrgyte","Element_Name":"textarea-201859","Count_Images":0,"req":0},  {"type":"dropdown","label":"dropdownbox","Element_Values":"d2","Element_Name":"dropdown-480200","Count_Images":0,"req":0,"choices":[{"label":"d1","sel":0},{"label":"d2","sel":0}]},
    {"type":"sub-header","label":"section3","Element_Values":"-","Element_Name":"sub-header-327336","Count_Images":0,"req":0},{"type":"checkbox","label":"checkbox","Element_Values":"[\"c1\",\"c2\"]","Element_Name":"checkbox-483738","Count_Images":0,"req":0,"choices":[{"label":"c1","sel":0},{"label":"c2","sel":0}]}, {"type":"radio","label":"radio","Element_Values":"\"r2\"","Element_Name":"radio-824113","Count_Images":0,"req":0,"choices":[{"label":"r1","sel":0}, {"label":"r2","sel":0}]},
    {"type":"description","label":"test template is here","Element_Values":"-","Element_Name":"description-764196","Count_Images":0,"req":0}]

```

If the type is checkbox or radio, get the Element\_Values and change the array choices according to Element\_Values.

```
{"type":"checkbox","label":"checkbox","Element_Values":"[\"c1\",\"c2\"]","Element_Name":"checkbox-483738","Count_Images":0,"req":0,"choices":[{"label":"c1","sel":0},{"label":"c2","sel":0}]}

```

Above, Element Values are c1 and c2. Then I need to change sel=1.
That is

```
"choices":[{"label":"c1","sel":1},{"label":"c2","sel":1}]}

```

Here another type radio is:

```
{"type":"radio","label":"radio","Element_Values":"\"r2\"","Element_Name":"radio-824113","Count_Images":0,"req":0,"choices":[{"label":"r1","sel":0},{"label":"r2","sel":0}]}

```

And the output should be:

```
{"type":"radio","label":"radio","Element_Values":"\"r2\"","Element_Name":"radio-824113","Count_Images":0,"req":0,"choices":[{"label":"r1","sel":0},{"label":"r2","sel":1}]}

```

I did the following code:

```
$c=json_decode($c);
foreach($c as $kc=>&$vc)
{
    if( $vc['type']=="checkbox" || $vc['type']=="radio")
    {
       $Val=$vc['Element_Values'];
       $choices=&$vc['choices'];
       foreach($choices as $key=>&$val)
       {
           if($val['label']==$Val)
           {
               $val['sel']=1;
           }
           unset($val['sel']);
       }
    }
}
echo json_encode($c);

```

I know it is a simple thing I am missing. Please help me to solve this. Thanks in advance!