How to fined the fields biggest weight in form I have made a content type in /admin/structure/types/add and then, created for this content type  extra fields from /admin/structure/types/manage/CONTENT TYPE_NAME/fields/add-field.
 After i created a module that will alter this content type by hook_form_BASE_FORM_ID_alter() in .MODULE file, and after i reset the default button that has content type that is SAVE button, and added new button:

    $form['register'] = array
  (
    '#type' =&gt; 'submit',
    '#value' =&gt; t('Register'),
    '#submit' =&gt; array('NAME_OF_A_FUNCTION'),
    '#weight' =&gt; '?',
  );


But when I do this the button is rendered first and after comes the content type fields. How to change the button row weight so that the button will always will show at the last plaice. In aver words how to get from all fields that has content type form and search for the biggest weight that has field and put this 'value + 1' in my new submit button '#weight' => '?'.
Dose anyone has solution for that... 
Thanks in advance
the solution is in this code: 

  $elements = Element::getVisibleChildren($form);
  $weight = 0;
  foreach ($elements as $el) {
    $check = strpos($el, 'field_');
    if ($check !== FALSE &amp;&amp; $form[$el]['#weight'] &gt;= $weight) {
      $weight = $form[$el]['#weight'];
    }
  }


  $form['register'] = [
    '#type' =&gt; 'submit',
    '#value' =&gt; t('Register'),
    '#submit' =&gt; array('NAME_OF_A_FUNCTION'),
    '#weight' =&gt; $weight + 1,
  ];