phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


PHP - Number: Finding the Smallest or Largest Number in an Unordered Series

Tag: number, smallest number, largest number   Category: PHP Application, PHP Basic
post: 16 Mar 2008 read: 45


PHP Number Tips - Part 5: In order to find the maximum or minimum value of a series of unordered numbers, you can arrange the numbers in sequence and then extract the endpoints of the sequence such as the following:

<?php
//define number series
$series = array(76, 7348, 56, 2.6, 189, 67.59, 17594, 2648, 1929.79,↵
54, 329, 820, -1.10, -1.101);

//sort array
sort($series);

//extract maximum/minimum value from sorted array
//result: "Minimum is -1.101 "
$min = $series[0];
echo "Minimum is $min ";

//result: "Maximum is 17594"
$max = $series[sizeof($series)-1];
echo "Maximum is $max";
?>

There are many ways in finding the smallest or larger value in a number series. In the above, the list demonstrates one of the simplest. The numbers are placed in an array and the sort( ) function is used to sort the array so that the numbers line up sequentially. The smallest value will end up at the beginning of the list while the largest will end up at the end of the list.




| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting