note 124903 added to function.array-key-last

From: Date: Sun, 12 Apr 2020 15:18:49 +0000
Subject: note 124903 added to function.array-key-last
Groups: php.notes 
Request: Send a blank email to php-notes+get-214460@lists.php.net to get a copy of this message
Now that we have this function, where we once used... <?php $idxLast = count($arr) - 1; ?> we can now optimize code speed by using... <?php $idxLast = (array_key_last($arr) ?? 0); ?> Use-cases include lots of looping and control-structures. If you do not know ahead of time that the array is numerically indexed, and that it could possibly be associative...safer/faster to stick with count(). ---- Server IP: 45.112.84.4 Probable Submitter: 38.142.137.34 (proxied: 96.61.135.240) ---- Manual Page -- http://php.net/manual/en/function.array-key-last.php Edit -- https://master.php.net/note/edit/124903 Del: integrated -- https://master.php.net/note/delete/124903/integrated Del: useless -- https://master.php.net/note/delete/124903/useless Del: bad code -- https://master.php.net/note/delete/124903/bad+code Del: spam -- https://master.php.net/note/delete/124903/spam Del: non-english -- https://master.php.net/note/delete/124903/non-english Del: in docs -- https://master.php.net/note/delete/124903/in+docs Del: other reasons-- https://master.php.net/note/delete/124903 Reject -- https://master.php.net/note/reject/124903 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#214460) next »