Php getting ten's value

If I have values

2014 I need to get the 14,

2022 I need to get the 22,

2122 I need to get 122,

I could do:

$value = 2000 - $value;

But what if it's

1014? where I need to get the 14?

Is there any way to get the ten's value of any number? or 100's value? Thanks


Yes there is. Use modulus:


echo 2014%1000;
echo 2022%1000;
echo 2122%1000;
echo 1014%1000;

Yes, there is:

$result = $value % 1000;

If they aren't necessarily numbers and you just want the two left values, you could also use:


$result = substr($value, -2);    // returns last two characters

Yes, If you use % , you can get the reminder value , if your value = 1234 , then 1234 % 1000 will return 234 , similarly it goes on.

$value = 1022 ; // your value

$tens value = $value % 1000;

echo $tens value ;

Need Your Help

Accessing web services

python web-services suds

I know there are many similar questions-solutions like this but none of solution working for me.

Use ack to find printing line in large project

regex ubuntu ack

So I have a very large project which when run prints a data set that is basicly this: