The last function returns the last element in the given array:
<?php $array = [100, 200, 300];

$last = last($array);
<?php     {

        $parts = explode('/', self::directory($path));



        return last($parts);

    }