How do you iterate over Matrix field in a Craft 3 plugin? $entry = Entry::find()-&gt;section('my_section')-&gt;relatedTo($entry)-&gt;all();
$entry['myMatrixField']; // What do I do with this??


I know there are tutorials about how to handle Matrix fields in plugins in Craft 2, but how do I do this in Craft 3?
If you had a Matrix field with a handle of matrix and it had a Matrix Block Type with a handle of MyMatrixBlock and it had a Plain Text field with a handle of text, this is how you'd grab it in PHP.

$entry = Craft::$app-&gt;getEntries()-&gt;getEntryById(2);

foreach ($entry-&gt;matrix as $matrixBlock) {
    if ($matrixBlock-&gt;getType()-&gt;name === 'MyMatrixBlock') {
        // Grab a text field from the block.
        $textField = $matrixBlock-&gt;text;
    }
}