tatlar
01-13-2004, 01:24 PM
I could use some guidance here. I think I have been looking at it too long and can't see what I am doing wrong. I think it is VERY simple... :D
I have an array (called $r1) with a series of values. I print this array to the screen with the following PHP and count the number of values in the array:
reset($r1);
while (list($key, $val) = each($r1)) {
echo "$key => $val<br>\n";
}
echo count( $r1 ) ;
It gives a count of 100 - all well and good.
The first value of the array is 200.
Now I want to convert all the values in the array using either sscanf or sprintf (I still don't really understand the difference between them!) and put all these converted values into a new array with the following PHP:
foreach ( $r1 as $range ) {
$range = sprintf( "%0.3f", ( $range ) ) ;
echo "Value => $range<br>\n";
}
So all the values in the original array are now converted and in the array called $range. With the echo function I print them all out just fine to the screen. However, after this when I try to count $range I get an answer of 1!!!
Echoing out the first array value of $range gives a value of 2!!!
It seems to me that the complete array has been converted into one long string. I did not want this to happen and am assuming it is because I am using sprintf? Can anyone help me out or tell me what I am doing wrong?
Thanks!
I have an array (called $r1) with a series of values. I print this array to the screen with the following PHP and count the number of values in the array:
reset($r1);
while (list($key, $val) = each($r1)) {
echo "$key => $val<br>\n";
}
echo count( $r1 ) ;
It gives a count of 100 - all well and good.
The first value of the array is 200.
Now I want to convert all the values in the array using either sscanf or sprintf (I still don't really understand the difference between them!) and put all these converted values into a new array with the following PHP:
foreach ( $r1 as $range ) {
$range = sprintf( "%0.3f", ( $range ) ) ;
echo "Value => $range<br>\n";
}
So all the values in the original array are now converted and in the array called $range. With the echo function I print them all out just fine to the screen. However, after this when I try to count $range I get an answer of 1!!!
Echoing out the first array value of $range gives a value of 2!!!
It seems to me that the complete array has been converted into one long string. I did not want this to happen and am assuming it is because I am using sprintf? Can anyone help me out or tell me what I am doing wrong?
Thanks!