darkhorn Posted September 17, 2009 Share Posted September 17, 2009 I have a big number such as 56781236 (8 digits long). And I want to find the integer that is in the fourth step, here it is 1. Or it could be from left, the fifth: 1. Link to comment https://forums.phpfreaks.com/topic/174576-how-to-find-the-number-of-a-given-location/ Share on other sites More sharing options...
kickstart Posted September 17, 2009 Share Posted September 17, 2009 Hi Treat it as a string and use substr("56781236", -4, 1). All the best Keith Link to comment https://forums.phpfreaks.com/topic/174576-how-to-find-the-number-of-a-given-location/#findComment-920049 Share on other sites More sharing options...
JonnoTheDev Posted September 17, 2009 Share Posted September 17, 2009 or $int = (string)56781236; print $int[4]; Link to comment https://forums.phpfreaks.com/topic/174576-how-to-find-the-number-of-a-given-location/#findComment-920162 Share on other sites More sharing options...
Philip Posted September 17, 2009 Share Posted September 17, 2009 Or if you don't want to convert it over: $var = 56781236; $int = (int) (($var%10000)/1000); // $int = 1 Please note that if your var isn't big enough it will just show 0... and doing it as a string[ ] will produce undefined index (I believe) You should check to make sure your value is big enough before applying any of these techniques. Link to comment https://forums.phpfreaks.com/topic/174576-how-to-find-the-number-of-a-given-location/#findComment-920168 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.