Adding to and Remove From a Relationship Field in PHP

Using add_to and remove_from to add items to a relationship field and remove items from a relationship.

<?php 
  //Adding and removing values from relationship fields
  
  //get pods object for book pod with an id of 5
  $pod = pods( 'book', 5 ); 
  
  //Get a field values from form submission 
  $new_value = $_POST['new_value']
  $delete = $_POST['delete']
  
  //if 'delete field' in form equals 1 delete value in relationship field
  //else set to value from 'new_value' field in form
  if ( $delete != 1 ) {
    //set new value for realtionship_field and return ID
    $id = $pod->add_to( 'relationship_field', 'new_value'  );
  else {
    //remove the value we just added if a conditonal is met 
    $id = $pod->remove_from( 'relationship_field' );
  }
  //return id of item modified
  return $id;
  
?>

Questions