Robin S Posted March 21, 2016 Posted March 21, 2016 There is a remove method for WireArray/PageArray that removes a single given item from the array. But how about removing all the items in one PageArray from another? So basically like PHP's array_diff for PageArray - any suggestions for this?
elabx Posted March 21, 2016 Posted March 21, 2016 I kind of had this problem, and solve it using a "NOT" selector when retrieving the array. https://processwire.com/talk/topic/12798-remove-multiple-items-from-pagearray/ Though I know this is not exactly what you are asking since it's not dealing exactly with the array, but thought it could help. 1
BitPoet Posted March 21, 2016 Posted March 21, 2016 $largePargeArray->removeItems($subsetPageArray); should work as PageArray inherits from WireArray. 5
Robin S Posted March 21, 2016 Author Posted March 21, 2016 Thanks for the replies. @elabx: Yeah, I'm already doing a similar workaround using the ->not method. $page_array_1 = $pages->find(selector_1); // do some stuff with $page_array_1 $page_array_2 = $pages->find(selector_2); // do some stuff with $page_array_2 // then to subtract $page_array_1 from $page_array_2... $page_array_2->not(selector_1); But it seems wrong to have to use the same selector again when you already have the PageArray you want to remove. I figured there has to be a better way... ...and there is, but it's not in the docs or cheatsheet. Thanks BitPoet.
szabesz Posted March 21, 2016 Posted March 21, 2016 ...and there is, but it's not in the docs or cheatsheet. Thanks BitPoet. I recommend using kongondo's ApiGen Docs, for example 3.x: http://kongondo.github.io/ProcessWireAPIGen/devns/class-PageArray.html Ryan's doc pages should be considered "for introduction purposes only". We cannot expect him to keep it up-to-date 2
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now