So I've created an array based on posted information (a big list of numbers separated by lines which has then been exploded)
So this array may contain numbers from 0-100
or whatever
So I have one array of numbers
Now for each number I want to find out many numbers are BELOW it in the entire array
So what I do is use foreach twice.
<?php
foreach($myarray as $n => $v) {
$total="";
foreach($myarray as $name => $value) {
if($value<$v) {
$total=$total+1;
}
}
echo $total;
}
?>
Right.
I know what the problem is but I don't know how to fix it!
When I use $value<$v, it gives the wrong total.
What it does, say $value = 20, and $v = 4, it thinks 20 is smaller than 4 - it's not a clever number. Say $v was 1, it would think it was smaller. It doesn't take the whole number into consideration.
It only doesn't work when $v is given as a variable, and not a static number.
if I did this...
<?php
foreach($myarray as $name => $value) {
if($value<4) {
$total=$total+1;
}
}
echo $total;
?>
It would work.
I'm not sure how well I've explained this but, yeah. Any ideas? Cheers!