note 78555 deleted from ref.array by levim
| From: | levim@php.net | Date: | Tue, 06 May 2014 22:09:04 +0000 |
| Subject: | note 78555 deleted from ref.array by levim | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-199465@lists.php.net to get a copy of this message | ||
Note Submitter: Hayley Watson
----
Regarding cyberchrist at futura dot net's function. It makes an unnecessary array_merge(); the
elements of $b that are merged with those of $a are immediately removed again by the array_diff().
The "limiting to known values" is entirely unnecessary, in other words: arrays already
only contain "known values".
Also, the description and function only address the issue of whether $a is a subset of $b, not
whether it is a proper subset. For $a to be a proper subset of $b, it must also be the case that $b
is not a subset of $a.
Taking those points into account (and a personal aesthetic dislike of "if(test) return true;
else return false;" gives:
<?php
function is_subset($a, $b)
{
return count(array_diff($a,$b))==0;
}
function is_proper_subset($a, $b)
{
return is_subset($a, $b) && !is_subset($b, $a);
}
?>