note 88938 deleted from function.next by danbrown

From: Date: Sat, 14 Feb 2009 05:53:28 +0000
Subject: note 88938 deleted from function.next by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-150649@lists.php.net to get a copy of this message
Note Submitter: Jordan ---- I've taken lukasz's solution below on finding the neighbors of keys and made it a bit more sensible (in my opinion): function getKeyBeforeKey($arr, $key) { $keys = array_keys($arr); $keyIndexes = array_flip($keys); if (isset($keys[$keyIndexes[$key]-1])) { return $keys[$keyIndexes[$key]-1]; } else { return false; } } function getKeyAfterKey($arr, $key) { $keys = array_keys($arr); $keyIndexes = array_flip($keys); if (isset($keys[$keyIndexes[$key]+1])) { return $keys[$keyIndexes[$key]+1]; } else { return false; } }

« previous php.notes (#150649) next »