Search code examples
phpstring-parsingdelimited

Get some digits from a string


I have the next strings:

generation_1_2
generation_2_8
generation_3_12

How can I put digits from this strings in variables?

For example:

$digit1[0] is 1.
$digit1[1] is 2.
$digit1[2] is 3.
$digit1[0] is 2.
$digit1[1] is 8.
$digit1[2] is 12.

Solution

  • function ret_int($str){
        return array_slice(explode('_', $str), 1);
    }