I'm not quite sure how to add $subject_id as a member of the $arr['subjects'] array. When I tried it without the count($arr['subjects]) line above and I was creating a unit with only a new subject name, the subject was added and showing up as pending, but the relation was not added to the units_subject table.