Q:

How to add a child node to array PHP

Im having a colomn in mysql table which contains array of data
{#369 ▼
  +"secondaryleader": "ddfsfsfsdfd"
  +"role": "Meet-LSV"
  +"activity": "2"
  +"rosterstart_time": "Fri Jan 05 2018 11:18:15 GMT+0530 (Sri Lanka Standard Time)"
  +"actualstart_time": "Fri Jan 05 2018 06:18:16 GMT+0530 (Sri Lanka Standard Time)"
  +"rosterfinish_time": "Fri Jan 05 2018 11:18:18 GMT+0530 (Sri Lanka Standard Time)"
  +"actualfinish_time": "Fri Jan 05 2018 11:18:19 GMT+0530 (Sri Lanka Standard Time)"
  +"uniformsetup_status": null
  +"uniformpackup_status": null
}

i have to add another array same as this when i am updating the table but this array shouldn't be deleted when i am adding the array comes like this
    {#369 ▼
  +"0": {#367 ▼
    +"0": {#371 ▶}
    +"2": {#372 ▼
      +"secondaryleader": "sdfsdfsf"
      +"role": "Meet-LSV"
      +"activity": "2"
      +"rosterstart_time": "Fri Jan 05 2018 11:18:15 GMT+0530 (Sri Lanka Standard Time)"
      +"actualstart_time": "Fri Jan 05 2018 06:18:16 GMT+0530 (Sri Lanka Standard Time)"
      +"rosterfinish_time": "Fri Jan 05 2018 11:18:18 GMT+0530 (Sri Lanka Standard Time)"
      +"actualfinish_time": "Fri Jan 05 2018 11:18:19 GMT+0530 (Sri Lanka Standard Time)"
      +"uniformsetup_status": null
      +"uniformpackup_status": null
    }
  }
  +"2": {#373 ▼
    +"secondaryleader": "vat69"
    +"role": "Meet-LSV"
    +"activity": "2"
    +"rosterstart_time": "Fri Jan 05 2018 11:18:15 GMT+0530 (Sri Lanka Standard Time)"
    +"actualstart_time": "Fri Jan 05 2018 06:18:16 GMT+0530 (Sri Lanka Standard Time)"
    +"rosterfinish_time": "Fri Jan 05 2018 11:18:18 GMT+0530 (Sri Lanka Standard Time)"
    +"actualfinish_time": "Fri Jan 05 2018 11:18:19 GMT+0530 (Sri Lanka Standard Time)"
    +"uniformsetup_status": null
    +"uniformpackup_status": null
  }
}

and my code is 
if($formArray->secondaryleader_details == ''||$formArray->secondaryleader_details == []){
  $merge_data=$data['secondaryleader_details'];
  $array= $merge_data;
}else{
  $arr_length = count($formArray->secondaryleader_details);
$new_array = ($arr_length+1);
  $merge_data=$data['secondaryleader_details'];
 $new_arr_data = array($merge_data);

 //$array=array_push($formArray->secondaryleader_details,$new_arr_data);
  // foreach ($new_arr_data as $mg) {
  $array=[$formArray->secondaryleader_details];
   $array[$new_array]= $merge_data;

A:

You can try:
$decoded_array = json_decode($array_from_db)

if(!$decoded_array){
    $decoded_array = [];
}

if(is_object($decoded_array)){
    $decoded_array = [$decoded_array];
}

$decoded_array[]=$new_data;

//save $decoded_array to database

