note 69460 deleted from ref.array by nlopess

From: Date: Thu, 07 Sep 2006 11:00:58 +0000
Subject: note 69460 deleted from ref.array by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-116820@lists.php.net to get a copy of this message
Note Submitter: four at fourfivetwofour dot com ---- Maybe I'm a doofus, or maybe a function like this isn't necessary in the 'real world', but I needed (and couldn't find) a function to get the KEY of the Longest VALUE in an Array. It could probably (definitely?) be done better, but I made this for the time being: <?php /* Get KEY of Longest (string) VALUE in an ARRAY... */ function array_get_longest($array) { $longest = 0; for($i=0; $i < count($array); $i++) { if (strlen($array[$i]) > strlen($array[$longest])) { $longest = $i; } } //return strlen($array[$longest]); // Length (string) of the Longest VALUE. return $longest; // KEY of Longest (string) VALUE. } ?> Please let me know if I've overlooked something, or if this could be done better. Thanks.

« previous php.notes (#116820) next »