Assign a group from logged in user contact group to new individual
If I understand it correctly you want to add contact (New individual) to a group of  logged in user, then i would write something like this

function search_civicrm_pre($op, $objectName, $id, &amp;$params) {
  if ($objectName == 'Individual' &amp;&amp; $op == 'create) {
    $groups = civicrm_api3('Contact', 'getsingle', [
      'return' =&gt; "group",
      'id' =&gt; 'user_contact_id',
    ])['groups'];
    foreach (explode(',', $groups) as $groupId) {
      $params['group'][$groupId] = 1;
    }
  }
}


HTH

Pradeep