Paldo Posted May 24, 2009 Share Posted May 24, 2009 Hi ! I want to ask you If its possible to transfer int to array somehow so I can work with seperate digits from this integer. I was thinking if there is some conversion Int to string, first couse I recall some command like this from other programing language and maybe it could be first step to do maybe, maybe not. What I need is a way to analyze digit, for example 136245 I want to know how many tousants are there how many hundrets and so on... This is the reason why I'm thinking about putting this numbers into array. I hope I made my selfe clear somehow. Quote Link to comment https://forums.phpfreaks.com/topic/159457-int-to-array-is-there-way-to-do-this/ Share on other sites More sharing options...
trq Posted May 24, 2009 Share Posted May 24, 2009 I want to know how many tousants are there how many hundrets and so on... All you need is simple maths. Quote Link to comment https://forums.phpfreaks.com/topic/159457-int-to-array-is-there-way-to-do-this/#findComment-841127 Share on other sites More sharing options...
wildteen88 Posted May 24, 2009 Share Posted May 24, 2009 Have a look at this post http://www.phpfreaks.com/forums/index.php/topic,252307.msg1185070.html#msg1185070 Seems similar to what you're trying to do. Quote Link to comment https://forums.phpfreaks.com/topic/159457-int-to-array-is-there-way-to-do-this/#findComment-841129 Share on other sites More sharing options...
Axeia Posted May 24, 2009 Share Posted May 24, 2009 If you're talking about casts $num = (int)'1221'; Would put the int in $num.. though most of the time php handles these kinds of things somewhat transparently as it doesn't support strong typing like most other languages. For example in java there is. int anInt = 0; While in php it's $int = 0; (notice the lack of data type) Quote Link to comment https://forums.phpfreaks.com/topic/159457-int-to-array-is-there-way-to-do-this/#findComment-841134 Share on other sites More sharing options...
Paldo Posted May 24, 2009 Author Share Posted May 24, 2009 Have a look at this post http://www.phpfreaks.com/forums/index.php/topic,252307.msg1185070.html#msg1185070 Seems similar to what you're trying to do. Could you be more specific please? Becouse What I originaly need to do is to transfer either string entred number or int into verbal form, for example 1874 ----> one thousand eight hundreat seventy four, and I have a strange feeling that there is som easy way to do that, however I'm not very good with maths. thanks Quote Link to comment https://forums.phpfreaks.com/topic/159457-int-to-array-is-there-way-to-do-this/#findComment-841165 Share on other sites More sharing options...
Mark Baker Posted May 24, 2009 Share Posted May 24, 2009 $intVal = 1874; $digitArray = str_split((string) $intVal); Quote Link to comment https://forums.phpfreaks.com/topic/159457-int-to-array-is-there-way-to-do-this/#findComment-841208 Share on other sites More sharing options...
shlumph Posted May 24, 2009 Share Posted May 24, 2009 I'm almost sure you could use the mod operator for this (%). Start large, work your way smaller. Quote Link to comment https://forums.phpfreaks.com/topic/159457-int-to-array-is-there-way-to-do-this/#findComment-841261 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.