|
Posted by Ivαn Sαnchez Ortega on 03/07/06 23:46
-----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.
- --
- ----------------------------------
IvΓ‘n SΓ‘nchez Ortega -i-punto-sanchez--arroba-mirame-punto-net
"All truth passes through three stages. First, it is ridiculed. Second, it
is violently opposed. Third, it is accepted as being self-evident."
- Arthur Schopenhauer (1788-1860)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
iD8DBQFEDf863jcQ2mg3Pc8RAn5MAJ9eJ+FYy7Zh6Dmr5O1UfkIIGdnLTwCbBmKZ
VD+NBSUgRGFj9HBbG206CSI=
=VWqE
-----END PGP SIGNATURE-----
[Back to original message]
|