I have a variable
$placement = "1st place"
What I want to do is take the number 1 and place it in another variable
$placement_num = "1";
Is this possible?
I have a variable
$placement = "1st place"
What I want to do is take the number 1 and place it in another variable
$placement_num = "1";
Is this possible?
If you know the numerical part is always right at the start of the string, you can just cast to int
:
$str = '1st place';
$num = (int) $str;
var_dump($num);
$str = '4th place';
$num = (int) $str;
var_dump($num);
This yields:
int(1)
int(4)