Entity Wrapper : how to delete multiple values field? I have a multiple values field on the user entity. This field is field_data.

There are several values in this field. I want to delete all of them.

I tried the following code:

for ($i = 0; $i &lt; count($user-&gt;field_data-&gt;value()); $i++) {
    $user-&gt;field_data[$i]-&gt;delete();
}


But I get errors about -&gt;delete() not being a method on this object. I also tried with -&gt;clear() to no avail.

I've been looking for examples on Google for how to do this, but my Google-fu is not so strong today.
Well, I solved it. The answer is kind of tricky.

You can't delete a value in a multiple values field. However, you can set it to "empty". When it's empty, it's removed.

Here is the code to use:

// Also, note the -&gt;count() method
for ($i = 0; $i &lt; $user-&gt;field_data-&gt;count(); $i++) {
  $user-&gt;field_data[$i]-&gt;set();
}


This way, values are now empty and the multiple fields have no value left. It's well shown in the UI too and the deltas are correctly handled in the database.