split($pattern,$string)
特定のパターンまたは正規表現内で文字列を分割します(5.3.0 以降は非推奨です)。
preg_split($pattern,$string)
指定された正規表現パターン内で文字列を分割します
explode($pattern,$string)
指定されたパターン内で文字列を分割する
end($arr)
配列の最後の要素を取得する
そう:
end(split('-',$str))
end(preg_split('/-/',$str))
$strArray = explode('-',$str)
$lastElement = end($strArray)
-
分離された文字列の最後の要素を返します。
そして、これを行うためのハードコアな方法があります:
$str = '1-2-3-4-5';
echo substr($str, strrpos($str, '-') + 1);
// | '--- get the last position of '-' and add 1(if don't substr will get '-' too)
// '----- get the last piece of string after the last occurrence of '-'