note 78555 added to ref.array

From: Date: Wed, 17 Oct 2007 11:10:58 +0000
Subject: note 78555 added to ref.array
Groups: php.notes 
Request: Send a blank email to php-notes+get-131448@lists.php.net to get a copy of this message
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); } ?> ---- Server IP: 203.89.181.186 Probable Submitter: 202.27.216.35 (proxied: 202.27.216.71) ---- Manual Page -- http://www.php.net/manual/en/ref.array.php Edit -- https://master.php.net/note/edit/78555 Del: integrated -- https://master.php.net/note/delete/78555/integrated Del: useless -- https://master.php.net/note/delete/78555/useless Del: bad code -- https://master.php.net/note/delete/78555/bad+code Del: spam -- https://master.php.net/note/delete/78555/spam Del: non-english -- https://master.php.net/note/delete/78555/non-english Del: in docs -- https://master.php.net/note/delete/78555/in+docs Del: other reasons-- https://master.php.net/note/delete/78555 Reject -- https://master.php.net/note/reject/78555 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#131448) next »