View Single Post
  #12  
Old 01-18-2014, 07:59 PM
100Zero100 100Zero100 is offline
Registered User
Join Date: Jul 2006
Posts: 31
100Zero100 is on a distinguished road
Quote:
Originally Posted by callimuc View Post
his one would just work at its best if you know/send the length of your numbers, while the one BlueMelon and me posted could be used as a function used by several scripts (like putting it into a class with custom functions)



Interesting to know
Starfire's method works with substring() too, for multiple numbers, by using temp.num.length() looping.

I disagree with everybody. I would use .charat()

PHP Code:
function numberToArray(num) {
 for (
temp.0num.length(); i++) {
  
temp.array.add(num.charat(i)); // like num.substring(i, 1) but more efficient
 
}
 return(array);

So
temp.num = 426;
temp.test = numberToArray(num);

temp.test is {4, 2, 6}

You could also use charat() to most efficiently get the number at a single position, eg num.charat(1) would be 2.

EDIT: Someone beat me to charat. Darn. But looping backwards and using .insert is the same as using .add and looping forwards, Andrew.

EDIT2: I wonder if concatenation/tokenize would be more efficient than .add()? If so, temp.array = array SPC num.charat[i]; + tokenize it on the return.
__________________
Hi. I'm NaS!

Last edited by 100Zero100; 01-18-2014 at 08:30 PM..
Reply With Quote