Edit report at https://bugs.php.net/bug.php?id=55505&edit=1
ID: 55505 Updated by: [email protected] Reported by: simon at spudley dot com Summary: Request for array subtraction operator. -Status: Open +Status: Wont fix Type: Feature/Change Request Package: Arrays related PHP Version: 5.3.8 Block user comment: N Private report: N New Comment: array_diff_key() already provides this functionality, and - is more ambiguous for PHP style arrays than a simple union: should it be the difference based on keys, values, or key/value pairs? I'm going to won't fix this here -- an RFC would be a more appropriate path forward for this, although I personally wouldn't support it even there. Previous Comments: ------------------------------------------------------------------------ [2011-08-25 09:48:45] simon at spudley dot com Description: ------------ The manual page http://www.php.net/manual/en/language.operators.array.php describes several operators available which work on array variables. This includes the addition (+) operator, which allows us to merge two arrays. I would suggest that a subtraction operator would also be useful. For example, let us say we have two arrays, one of which is a full list of available items, and the other is a list of items which have been used, and I want to find the list of items which haven't been used. An array subtraction operator would help with this. Test script: --------------- <?php //suggested use for array subtraction operator. $full_list = array('de'=>'some data', 'gr'=>'some data', 'tt'=>'some data'); //etc... $used_list = array('gr'=>'some data'); //etc... $unused_list = $full_list - $used_list; //would contain 'de' and 'tt', but not 'gr'. ?> Expected result: ---------------- $unused_list would contain the array elements from $full_list minus those present in $used_list. In the example code, this would mean $unused_list would contain 'de' and 'tt', but not 'gr'. Actual result: -------------- This is a feature suggestion, so the above code does not currently run. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=55505&edit=1
