FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Need help with stripping characters from numbers in array
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Need help with stripping characters from numbers in array [message #181009] Fri, 05 April 2013 16:01 Go to previous message
daveh is currently offline  daveh
Messages: 18
Registered: March 2013
Karma:
Junior Member
Hello

Given I have an array as such: (as an example)

Array ([0]=>+1.,[1]=>+2.,[2]=>-3.0,[3]=>A3B)

I want to return an array as such: Array ([0]=>1,[1]=>2,[2]=>3,[3]=>A3B)

basically if its a number remove leading + or - char from number and any decimal point but do not do anything with letters or anything with number and char combination such as 2B or A3 and so forth.

I can strip the numbers with this function:

$number = preg_replace("/[[:^digit:]]/", '', $number);

So basically I have to traverse an array element by element check if it is a number and if so strip it otherwise leave it alone and go to next and save the results into an array and the return that array. Or I can simply remove plus, minus or dot chars from every element. (that is all that I would need as that would cover every conceivable scenario)

Can someone suggest how to code this?

Thanks
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: C,C++ EMBEDDED SYSTEM, DSP CONSULTANT AVAILABLE
Next Topic: comparing arrays
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 28 04:24:38 GMT 2024

Total time taken to generate the page: 0.03816 seconds