note 107786 added to function.array-key-exists

From: Date: Mon, 05 Mar 2012 01:22:48 +0000
Subject: note 107786 added to function.array-key-exists
Groups: php.notes 
Request: Send a blank email to php-notes+get-186490@lists.php.net to get a copy of this message
If you want to take the performance advantage of isset() while keeping the NULL element correctly detected, use this: if (isset(..) || array_key_exists(...)) { ... } Benchmark (100000 runs): array_key_exists() : 205 ms is_set() : 35ms isset() || array_key_exists() : 48ms Note: The code for this check is very fast, so you shouldn't warp the code into a single function like below, because the overhead of calling a function dominates the overall performance. function array_check(...) { return (isset(..) || array_key_exists(...)) } ---- Server IP: 69.147.83.197 Probable Submitter: 183.178.37.239 ---- Manual Page -- http://www.php.net/manual/en/function.array-key-exists.php Edit -- https://master.php.net/note/edit/107786 Del: integrated -- https://master.php.net/note/delete/107786/integrated Del: useless -- https://master.php.net/note/delete/107786/useless Del: bad code -- https://master.php.net/note/delete/107786/bad+code Del: spam -- https://master.php.net/note/delete/107786/spam Del: non-english -- https://master.php.net/note/delete/107786/non-english Del: in docs -- https://master.php.net/note/delete/107786/in+docs Del: other reasons-- https://master.php.net/note/delete/107786 Reject -- https://master.php.net/note/reject/107786 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#186490) next »