I’ve a peculiar situation, I need to split variable into two parts [sign] and [number]
So I can have following integers (this is not a sequence, I can have only 1 integer at a time):
-15,...,-1,0,1,...,15
When there is minus sign I need to split it into [-] part and [integer] part when there is no sign I need [+] and [integer]
How would I do this?
I was thinking to use explode with explode(“-” but if there is no minus sign it will give errors… Any easy way to achieve what I want instead of writing multiple if functions?
For a single
integer, you can do the following:Which gives the output:
abs here is important if you want to remove the sign of the value.
Also, if you receive your value as a string, simply use intval