Array weirdness?
Hi, folks!
I must be misunderstanding something here....
I'm trying to fill an array, and sort it with the largest values at the top. What's got me puzzled is the way the array seems to be behaving....
During the process of filling the array elements, I see the values getting incremented, and such, but.... echoing the array element the SHOULD contain a 2, after the "filling loop" has finished, shows zero! I see it bump from 1 to 2, and then, after the filling loop, it's got 0....
Any help in de-mystifying this would be GREATLY appreciated!
Thanks for any pointers!
Joe
Here's the code:
{
$scount = array();
$scount[$i] = array_fill(0,100,0);
//Load array
// $records is the number of records from the db.
for ($i = 1; $i <= $records; $i++)
{
/*
$scode is the "stop code" from each record, a number between 0 and 100
*/
$tctr = $scode[$i];
//Increment the element that maps to this code
$scount[$tctr] ++;
//echo "<p> code=" . $tctr . "</p>";
//echo "<p> count=" . $scount[$tctr] . "</p>";
// next lines are test... show the value in one of the elements
if ($tctr == 41)
echo "<p> count=" . $scount[$tctr] . "</p>";
// .. shows twice, a 1 and a 2.....
}
//... and now the value is zero??
echo "<p> count=" . $scount[41] . "</p>";
// Now sort these puppies!
for($x = 1; $x <= 100; $x++)
{
for($y = 1; $y <= 100; $y++)
{
if($scount[$x] > $scount[$y])
{
$hold = $scount[$x];
$scount[$x] = $scount[$y];
$scount[$y] = $hold;
}
}
}
echo "<table>";
for ($i = 1; $i <= 10; $i++)
echo "<tr> <td class='a'>" . $scount[$i] . "</td> </tr>";
echo "</table>";
}
JP
__________________
JP
|