How to get the last character after the underscore of a string using PHP


This question already has an answer here:

  • PHP: Split string [duplicate] 7 answers

I need one small help. I need to echo the characters of a string which are after _ using PHP. Have a look at the example below.

$arr = "abcdef_123";

From the above example I need 123 which should be stored in another variable.

Please help me.

Try this code :

echo end(explode("_",$arr));