[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-general
Subject:    RE: [PHP] re: strip comma from $value
From:       "Matt Honeycutt" <matt () xpodesigns ! com>
Date:       2003-02-28 18:25:57
[Download RAW message or body]

I'm sorry, I missed a really big problem with what you're doing.

When you use foreach(), the value that it gives you (in your case, via the
$value variable) is not a reference to the array item, its a copy of it, so
modifying the copy doesn't modify your original array.

Use this (this should work):

for($i=0; $i < size($numeric_array); $i++) {
        if(strstr($numeric_array[$i],","))
        {
                $numeric_array[$i] =
ereg_replace(",","",$numeric_array[$i]);
                echo "comma stripped";
        }
}

Give that a shot and see what happens...

---Matt

-----Original Message-----
From: Jim Long [mailto:jim@jimlong.net]
Sent: Friday, February 28, 2003 12:00 PM
To: php
Subject: [PHP] re: strip comma from $value


Hi,

Thanks to those who are helping me.

Matt,

Same result, echo's sucess, but commas are still out put in the
$numeric_array.

Jim Long

Matt Wrote:

> foreach($numeric_array as $key => $value ) {
>         if(strstr($value,","))
>         {
>                 $value = ereg_replace(",","",$value);
>                 echo "comma stripped";
>         }
> }

Hugh Wrote:

>
> try ereg_replace(",","",$value);


Orignal post:

> Hi,
>
> I've figured out the way to solve my problem is to get rid of the commas
> before I sort.
>
> Trying to use this:
>
> //strip the commas-------
> foreach ($numeric_array as $key => $value) {
> if (stristr($value, ",")){
> //test to see if it worked
> echo("comma striped");
> }
> }
>
> --
>
> It passed the test but,
> I'm doing something wrong because the commas are still there.
>
> TIA,
> Jim Long
>
> Jim Long Wrote:
> > Does anyone know how to make the flag "sort_numeric" work?
> > Will it work with asort?
> >
> > asort ($numeric_array, SORT_NUMERIC);
> > I've tried this but it looks like it's having problems with the comma in
> > big numbers.
> > I'm not absolutely sure, but it looks like it's ignoring everything
> > after a comma when it sorts.
> >
>
>
> >
> > BTW: asort is the one I need as I must maintain the keys
> >
> > JanetVal Wrote:
> >
> > > sort() sorts by value but assigns new keys as numbers.
> > > asort() sorts by value, but keeps the same keys
> > > ksort() sorts by key.
> >
> > THANKS !

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic