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.
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.
If you want to extract the trailing numbers you can do:
if(preg_match_all('/(\d+)$/m',$input,$m)){
// $m[1] will have all the matches.
}
EDIT:
Answer to your edited question to extract both the digits:
$digit = array();
if(preg_match_all('/(\d+)\D*(\d+)$/m',$input,$m)) {
$digit = array_merge($m[1],$m[2]);
}