Add Tags to a Newly Created Entry With PHP in Craft 3 I am able to successfully create new entries with PHP when I am using basic field values that are Rich Text or Plain Text fields, but am unsure how to add Tags to an entry.

So my entry already has a field called 'tags' on it, and I thought that maybe it wanted an array of strings like so:

$entry-&gt;setFieldValues([
   'tags' =&gt; array('someCoolTag', 'tagasaurus rex')
]);


I admit I do not really understand how tags work behind the scenes, and would like to correct that. Any help is great.
Tags are normal Elements like Entries, Categories, Users and so on.. In order to relate a Tag to another element, you need to insert the array of those elements like you are used to with every other field

$existingTag = Tag::find()-&gt;title('whatever')-&gt;one();

$tag = new Tag();
$tag-&gt;groupId = 1; //&lt;-- insert your group id here
$tag-&gt;title = "something";
Craft::$app-&gt;getElements()-&gt;saveElement($tag);

$entry-&gt;setFieldValues([
   'tags' =&gt; [$tag-&gt;id, $existingTag-&gt;id]
]);