note 92704 deleted from function.count by googleguy

From: Date: Mon, 17 Sep 2012 00:09:38 +0000
Subject: note 92704 deleted from function.count by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-190826@lists.php.net to get a copy of this message
Note Submitter: ravenswd at gmail dot com ---- The code snippet posted by legobuff at hotmail dot com on 02-Feb-2000 contains an error. This is the code that was posted: <?php // To find the index of the last element in the array: end($yourArray); $index = key($yourArray); ?> However, this will fail if the indices have been stored out of sequence. What you actually want is max(array_keys($yourArray)), as indicated below: <?php $yourArray = array(1=>'a', 7=>'b', 5=>'c'); print count($yourArray); // prints 3 end($yourArray); print key($yourArray); // prints 5 print max(array_keys($yourArray)); // prints 7 ?>

« previous php.notes (#190826) next »