getting top and bottom numbers

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mccommunity
Forum Commoner
Posts: 62
Joined: Mon Oct 07, 2002 8:55 am

getting top and bottom numbers

Post by mccommunity »

Is there a function in that will grab the top number out of and array and the bottom number?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

like LBound and UBound in visial basic? Not that I know of.
But you might take the array keys, sort them and use the first and the last entry

Code: Select all

<?php
$arr = array(
		9=>'i',
		5=>'e',
		25=>'y',
		12=>'l'
	);
	
$keys = array_keys($arr);
sort($keys);
echo $keys[0], '...', $keys[count($keys)-1];
?>
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

If the array isn't multidimensional, but just simple like
array(1,4,6,3,4,8) you can do

Code: Select all

$foo = array(7,4,9,2,4,3,1);
echo min($foo);
echo max($foo);
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

oops, I probably missed the point ;)
Post Reply