Page 1 of 1

getting top and bottom numbers

Posted: Thu Oct 23, 2003 8:30 am
by mccommunity
Is there a function in that will grab the top number out of and array and the bottom number?

Posted: Thu Oct 23, 2003 9:19 am
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];
?>

Posted: Thu Oct 23, 2003 9:27 am
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);

Posted: Thu Oct 23, 2003 9:37 am
by volka
oops, I probably missed the point ;)