note 98305 added to function.is-array
| From: | JTS at osu1 dot php dot net | Date: | Tue, 08 Jun 2010 11:22:19 +0000 |
| Subject: | note 98305 added to function.is-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-169936@lists.php.net to get a copy of this message | ||
I would change the order of the comparison, because if it is really an empty array, it is better to
stop at that point before doing several 'cpu & memory intensive' function calls.
In the end on a ratio of 3 not empty arrays to 1 empty array computed for 1000000 iterations it
needed 10% less time.
Or the other way round:
It needed approx 3% to 4% more time if the array is not empty, but was at least 4 times faster on
empty arrays.
Additionally the memory consumption veritably lesser.
<?php
function is_assoc($array) {
return (is_array($array) && (count($array)==0 || 0 !== count(array_diff_key($array,
array_keys(array_keys($array))) )));
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 85.181.81.209
----
Manual Page -- http://www.php.net/manual/en/function.is-array.php
Edit -- https://master.php.net/note/edit/98305
Del: integrated -- https://master.php.net/note/delete/98305/integrated
Del: useless -- https://master.php.net/note/delete/98305/useless
Del: bad code -- https://master.php.net/note/delete/98305/bad+code
Del: spam -- https://master.php.net/note/delete/98305/spam
Del: non-english -- https://master.php.net/note/delete/98305/non-english
Del: in docs -- https://master.php.net/note/delete/98305/in+docs
Del: other reasons-- https://master.php.net/note/delete/98305
Reject -- https://master.php.net/note/reject/98305
Search -- https://master.php.net/manage/user-notes.php