Get last 4 digits from Credit card number magento 2.

You can get last 4 digits from a credit card using Magento 2 when you worked with payment method extension or modification to payment method.

You need last four digits to show the payment credit card number in customer order’s payment details.

For Display purpose, You can show last four digits as per below code snippets,

<?php

public function getCcLast4() {
    $ccNumber = '4111111111111111';
    $ccLast4 = substr($ccNumber, -4);
    return $ccLast4;
}

When you call the above method, $this->getCcLast4() you got the last four digits of cc number.

Output:
1111