Studio Lambelet Posted May 30, 2022 Share Posted May 30, 2022 I'm working on a module that extends FieldtypeMulti, with the same way of storing data as FieldtypePagetable (field value is a WireArray). I used without any issues WireArray->add(), WireArray->prepend() or WireArray->insertAfter() but WireArray->remove() doesn't seem to work. Here is a minimal test case (tested in module init(), PW version 3.0.200) $array = wire(new WireArray); $array->add('Foo'); $array->add('Bar'); $array->add('Baz'); bd($array); /** * ProcessWire\WireArray * count: 3 * items: array * 0 => 'Foo' * 1 => 'Bar' * 2 => 'Baz' */ $array->remove('Foo'); // $newArray = $array->remove('Foo'); does the same... bd($array); /** * ProcessWire\WireArray * count: 3 * items: array * 0 => 'Foo' * 1 => 'Bar' * 2 => 'Baz' */ I would expect the WireArray to remove the element and update the count. But alas, it's not doing anything. Does anyone with an idea of what I don't understand here? Thanks! Link to comment Share on other sites More sharing options...
elabx Posted May 30, 2022 Share Posted May 30, 2022 remove() takes the key as argument, not the value. I'd wonder, if the WireArray is numerically indexed, would there be a way to use a selector to find the item to delete first? 2 Link to comment Share on other sites More sharing options...
Studio Lambelet Posted May 31, 2022 Author Share Posted May 31, 2022 Thanks elabx! I read the documentation a bit too quickly ? For anyone having the same misunderstanding in the future, I solved it by using PHP array_search(). 1 Link to comment Share on other sites More sharing options...
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