Tuesday, August 4, 2009

PHP - Find min and max values in an array

/**
signature
array getMinMax( array )

returns an associative array with:
'min' -> smallest value in the given array
'max' -> greatest value in the given array

if the array is empty both fields are NULL
*/
function getMinMax($array)
{

reset($array);
if(
FALSE === key($array))
{
return array(
'min' => NULL, 'max' => NULL);
}

$min = $max = current($array);
$val = next($array);

while(
NULL !== key($array))
{
if(
$val > $max)
{
$max = $val;
}
elseif(
$val < $min)
{
$min = $val;
}
$val = next($array);
}
return array(
'min' => $min, 'max' => $max);
}


Usage:

$min_max_arr = getMinMax($myarray);

$min_val = $min_max_arr['min'];
$max_val = $min_max_arr['max'];

(found here -- http://www.codingforums.com/showthread.php?t=130494)

Example application -- If you had an array of dates, you could turn each entry into a timestamp, run the array of timestamps through this function, and get the minimum and maximum timestamps. Then you could simply convert the min and max timestamps back to a string (using something like strftime).

22 comments:

Anonymous said...

I have had an iPhone for about 5 months now - and i am unable to work out how to turn Geotagging on and off - and how to show the geo data. I have been searching online for answers but have been unable to find anything of any use. Can anyone help?



________________
[url=http://unlockiphone22.com]unlock iphone[/url]

Anonymous said...

A threatening family member is claiming that she can find where I am staying via gps.All I want is to hide my iphone from gps tracking.Is there any way I can do that?



________________
[url=http://unlockiphone22.com]unlock iphone[/url]

Anonymous said...

Nackte Amateure

Webcam Erotikchat

Cam Girls

Anonymous said...

[url=http://www.blingforfun.com]hip hop jewelry[/url],[url=http://www.blingforfun.com/pendants/cat_9.html]hip hop pendants[/url],hip hop watches,[url=http://blingforfun.com/belts/cat_18.html]bling bling[/url] ,hip hop,[url=http://blingforfun.com/chains/cat_7.html]hip hop chains[/url],hip hop bling,[url=http://blingforfun.com/chains/cat_7.html]iced out chains[/url],[url=http://www.blingforfun.com/chains/cat_7.html]wholesale chains[/url]
hip hop jewelry
wholesale hip hop watches
hip hop rings

unlock iphone 2g said...

I have an iPhone 3g with 3.1.2 and firmware 05.11.07. I have downloaded blackra1n to jailbreak and it worked great. But I am leaving to Hong Kong soon and I really hope it will work as an unlock too.
________________
[url=http://www.unlock-iphone.org]unlock iphone 2g[/url]

viagra online said...

this kind of topic is good for people to learn more about it, and that people should be every day less ignorant, and medicine for this is the reading of issues like this

niz said...

Hello .. firstly I would like to send greetings to all readers. After this, I recognize the content so interesting about this article. For me personally I liked all the information. I would like to know of cases like this more often. In my personal experience I might mention a book called Generic Viagra in this book that I mentioned have very interesting topics, and also you have much to do with the main theme of this article.

Anonymous said...

new jersey state board of pharmacy newslwtter http://usadrugstoretoday.com/products/biaxin.htm physician dealing with compounding pharmacy [url=http://usadrugstoretoday.com/products/allopurinol.htm]allopurinol[/url]
pharmacy jobs nh http://usadrugstoretoday.com/products/betnovate.htm priceline pharmacy [url=http://usadrugstoretoday.com/products/tretinoin-cream-0-025-.htm]doctorate in pharmacy and health services[/url]

Anonymous said...

konrad zuse matrix movie http://moviestrawberry.com/films/film_riverworld/ the animal movie [url=http://moviestrawberry.com/films/film_stuart_little_3_call_of_the_wild/]stuart little 3 call of the wild[/url]
free downloadable xxx full lenth movie http://moviestrawberry.com/films/film_evil_under_the_sun/ best movie 1979 [url=http://moviestrawberry.com/films/film_her_cardboard_lover/]movie graham nc[/url]
transformers movie paramount stars http://moviestrawberry.com/films/film_diamond_dogs/ windows movie maker [url=http://moviestrawberry.com/films/film_honey_harvester/]honey harvester[/url]
black sex free movie sample http://moviestrawberry.com/films/film_the_last_confession_of_alexander_pearce/ illegal tender the movie [url=http://moviestrawberry.com/hqmoviesbygenres/download-genre_drama-movies/?page=1]black airplane movie[/url]
the simpsons movie dvd http://moviestrawberry.com/films/film_the_untouchables/ sandra bullock cyber movie [url=http://moviestrawberry.com/films/film_my_own_worst_enemy/]my own worst enemy[/url]
movie water fire earth reply http://moviestrawberry.com/films/film_dead_end/ legend of zelda movie [url=http://moviestrawberry.com/hqmoviesbyyear/year_1937_high-quality-movies/]the flying scotsman movie[/url]

Anonymous said...

software deals disk warrior http://freshoemsoftware.com/category-200-208/product-16754/TextSoap-5-7-Mac nero express cd burn software [url=http://downloadoemsoftware.us/oem-software/audio-transcoder-1.7.html]audio transcoder 1.7[/url]
Thomson Endnote X 10 http://goldoemsoftware.com/legal-software/dentimax-v1.1.html most effective windows firewall software effective [url=http://freshoemsoftware.com/category-100-108/Office-Tools]software serial numbers[/url]
PrimaSoft Church Library Organizer Pro 2.2 http://freshoemsoftware.com/de/category-7/product-30883/Richardson-Software-RazorSQL-5-0 wizzard software [url=http://freshoemsoftware.com/fr/category-3/product-12931/Amabilis-3D-Canvas-Pro-6-0]Amabilis 3D Canvas Pro 6 0[/url]
music harmony training software freeware http://freshoemsoftware.com/de/category-100-107/product-19774/Altova-MapForce-Enterprise-2009 Adobe Premiere Professional CS4 [url=http://freshoemsoftware.com/fr/manufacturer-9/product-16867/AutoCAD-2009-32-bit]computer audio recording software for mac[/url]
best free uninstalling software http://freshoemsoftware.com/fr/category-100-104/product-12387/Panopticum-AlphaStrip-v1-33-for-Adobe-Photoshop-CS2 slovo ed software [url=http://freshoemsoftware.com/de/product-17215/Disco-1-0-Mac]Disco 1 0 Mac[/url]
palm powered software http://freshoemsoftware.com/it/category-7/product-14586/PrimalScript-3-1 encryption software [url=http://freshoemsoftware.com/de/category-100-113/product-19765/AdmixDJ-2-2]free quickbooks edition simple business start starter software network downloads[/url]

Anonymous said...

lan notification area icon software http://freshoemsoftware.com/de/category-12/product-17322/Active-MediaMagnet-5-6 Microsoft SharePoint Designer Technical Preview 2010 x64 [url=http://freshoemsoftware.com/category-100-102/product-18586/Rosetta-IT-Solutions-Business-Planner-Pro-8-0]Rosetta IT Solutions Business Planner Pro 8 0[/url]
free avg software http://freshoemsoftware.com/it/product-17502/iBank-Mac WebPosition Gold Pro 2.0 [url=http://freshoemsoftware.com/it/category-7/product-15167/Caphyon-Advanced-Installer-Enterprise-4-5]open source software versus proprietary software[/url]
construction accounting software http://freshoemsoftware.com/de/category-3/product-12264/VirtualDub-1-7 autonomy and software [url=http://freshoemsoftware.com/fr/category-100-112/product-11150/Advance-WMA-Workshop-2]Advance WMA Workshop 2[/url]
Alchemy Catalyst Developer Edition 8.0 http://freshoemsoftware.com/es/product-27680/Avanquest-Double-Anti-Spy-Pro-1-2 time tracking software [url=http://freshoemsoftware.com/fr/category-10/product-14552/CodeCharge-Studio-4-0]free wifi signal locater software[/url]
web shop software http://freshoemsoftware.com/es/category-100-102/product-10384/Credit-Money-Machine-3-5 Dameware Nt Utilities 6.8 [url=http://freshoemsoftware.com/de/category-100-102/product-12946/Trados-MultiTerm-7-Desktop]Trados MultiTerm 7 Desktop[/url]
garmin gps software http://freshoemsoftware.com/fr/category-14/product-24849/WONDERTOUCH-PARTICLEILLUSION-SE-2-0 northrop grumman gis software jogs [url=http://freshoemsoftware.com/de/category-14/product-10515/Adolix-PDF-Converter-3-2]software to alter song speed[/url]

Anonymous said...

pharmacy techincian http://zebba.eu/pain-relief/pain-relief-for-dogs first pharmacy school [url=http://zebba.eu/pyridostigmine/pyridostigmine-bromide-usp]pyridostigmine bromide usp[/url]
pharmacy technician jobs maryland http://zebba.eu/omeprazole/long-term-effects-of-generic-omeprazole mirapex mail order pharmacy [url=http://zebba.eu/omeprazole/omeprazole-delayed]walmart pharmacy 27th milwaukee[/url]
self service photo pharmacy http://zebba.eu/famvir/famvir-pravachol-protonix-nasonex-combivent online pharmacy australia [url=http://zebba.eu/indomethacin/indomethacin-and-gout]indomethacin and gout[/url]
pravachol phentermine pet pharmacy http://zebba.eu/fda/fda-foodborne-illness-sampling-kits pharmacy gold card [url=http://zebba.eu/vpxl/viramune-annual-us-sales]delmar pharmacy[/url]
helios homeopathic pharmacy uk http://zebba.eu/voltaren/is-it-safe-to-take-l-carnitine-with-voltaren how to check on an online pharmacy [url=http://zebba.eu/insomnia/cafe-insomnia]cafe insomnia[/url]
medical alternatives infusion pharmacy services http://zebba.eu/voltaren pharmacy inventory hospital [url=http://zebba.eu/vytorin/vytorin-mouth-sores]college of pharmacy in canada[/url]

Anonymous said...

agency online travel uk http://bank.bonox.eu/national-bank-of-monterial altitude travel [url=http://advance.bonox.eu/neosure-advance]neosure advance[/url]
top rated travel insurance http://bankruptcy.bonox.eu/new-bankruptcy-law-and-credit-card-debt europe motorhome travel [url=http://credit.bonox.eu/att-universal-credit-card-login]italy travel pictures[/url]
discount air travel to montreal http://business.bonox.eu/start-a-automatic-withdrawal-business travel food warmer [url=http://business.bonox.eu/business-practices]business practices[/url]
neuss germany travel information http://business.bonox.eu/measures-of-income-measurement-for-business travel trade linda mick azamara lines richard fain [url=http://finance.bonox.eu/my-way-finance]travel dog crates[/url]
travel jewerly tote http://bankruptcy.bonox.eu/hoe-will-bankruptcy-affect-my-chance-of-gettting-an-equity-loan national travel [url=http://credit.bonox.eu/credit-for-airline-mileage]credit for airline mileage[/url]
pet voyager travel crate http://finance.bonox.eu/barclay-finance-security amelia island travel info [url=http://visa.bonox.eu/tobago-visa-requirement]travel lodge wickliffe ohio[/url]

Anonymous said...

treasure coast pharmacy http://icepharmacy.in/bath-salt/homemade-craft-gift organic pharmacy [url=http://icepharmacy.in/cellulite/reducing-cellulite]reducing cellulite[/url]
jackson memorial hospital residency pharmacy miami http://icepharmacy.in/holistic/holistic-vets pharmacy technician home study program [url=http://icepharmacy.in/abdominal/fitness-exercise-care-abdominal-personal-and-equipment]math questions for pharmacy technicians[/url]
online usa pharmacy no prescription http://icepharmacy.in/exercise/exercise-example-and-pilates pharmacy technician schools kamloops [url=http://icepharmacy.in/acne/clera-light-acne-cure]clera light acne cure[/url]
list of pharmacy colleges http://icepharmacy.in/cellulite/remedies-for-cellulite pharmacy penegra weight loss silagra cumwithus c [url=http://icepharmacy.in/beauty/beauty-control-products]pre pharmacy programs[/url]
drugs online pharmacy http://icepharmacy.in/bodybuilding/bodybuilding-blender-recipes ainsworths homoeopathic pharmacy [url=http://icepharmacy.in/bodybuilding]bodybuilding[/url]
model data flow diagram of a pharmacy http://icepharmacy.in/homeopathy/polycythemia-and-homeopathy alltown pharmacy eatontown nj [url=http://icepharmacy.in/acupuncture/acupuncture-mass]online pharmacy flonase[/url]

Anonymous said...

rock autoparts http://legalmusicworld.in/soundtrack/soundtrack-for-shallow-hal waves chorus [url=http://legalmusicworld.in/rap/rap-video-dancer]rap video dancer[/url]
ezvision ipod http://legalmusicworld.in/dance/dance-slasa-colorado-springs old alarm clock ringtone [url=http://legalmusicworld.in/rap/star-war-gangster-rap-2]hilary clinton country music[/url]
electric pop corn makers http://legalmusicworld.in/soul/james-brown-the-godfather-of-soul lil prince 1st birthday [url=http://legalmusicworld.in/pop/partition-pop-ttbb]partition pop ttbb[/url]
chamillionaire murder music video http://legalmusicworld.in/hip-hop/free-hip-hop-buisness-software-downloads frank caliendo ringtones [url=http://legalmusicworld.in/music/music-song-video-goldfish-animal-rights]free audio sownloads[/url]
care for animals in little rock http://legalmusicworld.in/mp3/ray-stevens-mp3s karen tyler wins 2007 blues [url=http://legalmusicworld.in/gothic/gothic-and-punk-pants]gothic and punk pants[/url]
installing knobs on kitchen cabinet doors http://legalmusicworld.in/pop/computer-pop-up-desk-calender the hallelujah chorus portland oregon [url=http://legalmusicworld.in/gothic/gothic-graphic-art]nobuo uematsu tatakau mono tachi sheet music[/url]

Anonymous said...

westbury pharmacy three chopt http://health-life.kqv.in/angel-of-good-health sterling pharmacy stratford nj [url=http://blood-cells.kqv.in/complete-blood-count-weakness-dizziness-side-effects]complete blood count weakness dizziness side effects[/url]
how to pick a jury for a pharmacy trial http://diabetes-type.kqv.in/treatment-information-for-diabetes access pharmacy [url=http://health-care.kqv.in/veronica-michie-howard-county-health-department]internet pharmacy bulletin boiards[/url]
pharmacy resources http://heart-rate.kqv.in/the-function-of-the-heart harvey pharmacy perth [url=http://heart-medicine.kqv.in/heart-rate-chart-workout]heart rate chart workout[/url]
mexico nogales pharmacy http://canada-pharmacy.kqv.in/maple-leaf-pharmacy-seattle pharmacy laws schedule ii prescription [url=http://heart-rates.kqv.in/heart-rate-glycogen-fat]amana ia pharmacys[/url]
sample outline for pharmacy school essays http://heart-medicine.kqv.in/congestive-heart-failure-dogs orange belt pharmacy [url=http://health-centers.kqv.in/health-strange-death]health strange death[/url]
order tadalafil pharmacy http://canada-pharmacy.kqv.in/marrakech-argane-face-cream-pharmacy clinical provider pharmacy systems [url=http://women-health.kqv.in/springfield-health-department]longs auburn elm pharmacy[/url]

Anonymous said...

f4815a hp usb optical travel mouse manual guide style
microsoft reported earningsq207 mp3
pantie hose movie porn
romania travel tourism
alicia keys you and me together

Anonymous said...

ziggy time travel http://philodendron.dnst.info/philodendron-sizes-of philodendron sizes of [url=http://zantedeschia.dnst.info/zantedeschia-carmine-red]zantedeschia carmine red[/url]
http://pussy-willow.dnst.info/pussy-willow-bulk-lot pussy willow bulk lot rock band still water [url=http://tulipa.dnst.info/tulipa-greigii]tulipa greigii[/url]
[url=http://lisianthus.dnst.info/lisianthus-flowers]lisianthus flowers[/url] george clooney movie http://tuberose.dnst.info/jo-malone-tuberose jo malone tuberose
discount travel swinger resorts mexico http://sweet-william.dnst.info/sweet-william-family-restaurant sweet william family restaurant [url=http://wattle.dnst.info/red-wattle-swine]red wattle swine[/url]
http://wattle.dnst.info/spike-wattle spike wattle kissimmee state rock monument [url=http://myrtus.dnst.info/myrtus-reed-oregon]myrtus reed oregon[/url]

buy generic cialis online said...

Well worth to read this article, thanks for sharing this information. With this article you offered me got a chance to know about this, anyway i say Great Article! and waiting for you next article about this interesting subject.

phone cards said...

great source about code ) thanks

Dave said...

These kind of post are always inspiring and I prefer to read quality content so I happy to find many good point here in the post, writing is simply great, thank you for the post penis enlargement penis enlargement pills VigRX Plus

jimmy jam said...

We have an occasional patient with OHSS in the hospital and once in a while we have an ectopic pregnancy that requires laparoscopy but most of the time there are not a lot of medical surprises. Canine Cataracts