Posted: Thu May 31, 2007 8:13 pm
Or, if it's already sorted:Jcart wrote:3. is there a way to extract just the largest integer?Code: Select all
rsort($data); echo $data[0];
Code: Select all
echo $data[sizeof($data) - 1];A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Or, if it's already sorted:Jcart wrote:3. is there a way to extract just the largest integer?Code: Select all
rsort($data); echo $data[0];
Code: Select all
echo $data[sizeof($data) - 1];array_count_values() wrote:array_count_values() returns an array using the values of the input array as keys and their frequency in input as values.
Code: Select all
$predata = explode(", ", $_POST['data']);
$data = array_count_values($predata);
echo 'Mode: '.$data.'';Yes... Did you read?tail wrote:i used this but it outputted "Array" instead of the most common integer
feyd wrote:array_count_values() wrote:array_count_values() returns an array using the values of the input array as keys and their frequency in input as values.
Code: Select all
$predata = explode(", ", $_POST['data']);
$data = array_count_values($predata);
var_dump($predata, $data);Code: Select all
array(6) { [0]=> string(1) "1" [1]=> string(1) "2" [2]=> string(1) "3" [3]=> string(1) "1" [4]=> string(1) "2" [5]=> string(1) "3" } array(3) { [1]=> int(2) [2]=> int(2) [3]=> int(2) }array_count_values() returns an array means that whatever you pass to the array_count_values() function, if successfully able to evaluate it, will result in an array coming back to you.array_count_values() returns an array using the values of the input array as keys and their frequency in input as values.
Code: Select all
<?php $input = array('cat', 'dog', 'cat', 'cat', 'dog', 'big dog', 'angry elephant', 'sexy penguin'); ?>Code: Select all
Array (
[0] => cat,
[1] => dog,
[2] => cat,
[3] => cat,
[4] => dog,
[5] => big dog,
[6] => angry elephant,
[7] => sexy penguin
)Code: Select all
<?php $array = array_count_values($input); ?>Code: Select all
Array (
[cat] => 3,
[dog] => 2,
[big dog] => 1,
[angry elephant] => 1,
[sexy penguin] => 1
)the thing about the numbers is, i'm trying to create a script where it finds the mean(avg of inputted numbers), median(middle of inputted numbers), and mode(most common inputted number). that is why i'm using numbers.feyd wrote:Look at it in the browser's source, not the browser. It should be fairly clear if you used more meaningful values than numbers too.
Yeah that's true. I think feyd may have meant to test it on something with values other than numbers so you'd be able to see it better, but Everah's post probably cleared that up for you.tail wrote:the thing about the numbers is, i'm trying to create a script where it finds the mean(avg of inputted numbers), median(middle of inputted numbers), and mode(most common inputted number). that is why i'm using numbers.feyd wrote:Look at it in the browser's source, not the browser. It should be fairly clear if you used more meaningful values than numbers too.