Reputation: 310
Okay. Say I have string
'193'
And I want to remove the last numbers and store them in an array so I can do operations with them. I know substr can delete the 2 characters, but I'm not sure how to store them after they've been removed..
Upvotes: 5
Views: 32190
Reputation: 1453
Why not treat it as a number (your question said it's a numeric string) ?
$last2 = $str%100;
Upvotes: 5
Reputation: 5885
$str = "193";
$str_array = str_split($str);
$number_1 = array_pop($str_array); //3
$number_2 = array_pop($str_array); //9
Upvotes: 0
Reputation: 15290
$array = str_split('193'); // $array now has 3 elements: '1', '9', and '3'
array_shift($array); // this removes '1' from $array and leaves '9' and '3'
Upvotes: 0