Jump to content

Comparing


Guest

Recommended Posts

Well, if you don't [b]have[/b] to keep the array in the same order, just run a sort() on it and echo the first value:
[code]
<?php
$nums = array(100, 300, 24, 40);
sort($nums);
echo $nums[0];
?>
[/code]

Otherwise, you'd need to do some sort of looping comparison like this:
[code]
$nums = array(100, 300, 24, 40);
$small = $nums[0]; // default to the first value
foreach ($nums as $num) {
  $small = $num < $small ? $num : $small;
}

echo $small; // holds the smallest value in the array
[/code]

Hope that helps!
Link to comment
https://forums.phpfreaks.com/topic/29387-comparing/#findComment-134783
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.