|
Posted by David Haynes on 03/08/06 00:23
Iván Sánchez Ortega wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> David Haynes wrote:
>
>> A brute force method:
>> for( $i = 0; $i < count($array_with_numbers); $i++) {
>> str_replace(',', '.', $array_with_numbers[$i];
>> }
>
> Never use a for(;;) loop to iterate over an array: you are creating
> error-prone code.
>
> Either use foreach() with references:
> <?php
> foreach($array_with_numbers as &number)
> str_replace(',', '.', $number);
> ?>
>
> Or use array_map to automatically transverse the array applying a function
> to every element, or (even better) use a recursive function.
>
> Or, you can RTFM. http://php.net/str_replace , the part that says:
>
> "If subject is an array, then the search and replace is performed with every
> entry of subject, and the return value is an array as well."
>
>
> So, please go RTFM.
I suspect you are having a bad day.
Iteration by indexing works and is, as I said, brute force.
-david-
Navigation:
[Reply to this message]
|