<p><code>MultiOptionsFieldData</code> extends PHP's <a href="https://www.php.net/manual/en/class.arrayobject.php" rel="nofollow noreferrer">ArrayObject</a> class.</p>

<p>You could get the values from it by casting it to an array like so:</p>

<pre><code>$results = (array)$mofd;
</code></pre>

<p>That would give you an array of <code>OptionData</code> classes.  If you really didn't want to loop through them, you could do something like:</p>

<pre><code>$func = static function($ofd) {
    return $ofd-&gt;value;
};

$results = array_map($func, (array)$mofd);
</code></pre>

CC BY-SA 4.0
2019-07-29T20:15:47.763Z
Yeah, getting the array of OptionData instances was as close as I got but I was hoping for just the array of string values. Thanks, Brad. I think a method to obtain the raw value on the MultiOptionsFieldData class might be helpful in situations like this. Maybe something like:

$entry->getFieldValue('diningCuisine')->rawValue()
Benjamin Kohl
CC BY-SA 4.0
2019-07-29T19:01:49.490Z
2019-07-29T19:01:49.490Z
Brad Bell
<p>Another option for getting the string values as an array after typecasting the <code>MultiOptionsFieldData</code> object as an array:</p>

<pre><code>$values = ArrayHelper::getColumn(ArrayHelper::toArray( (array) $entry-&gt;getFieldValue('diningCuisine') ), 'value');
</code></pre>

CC BY-SA 4.0
2019-07-29T20:33:42.700Z
2019-07-29T20:33:42.700Z
Benjamin Kohl
<p>I have a checkbox field for dining cuisine types and I see that the checked options are stored as a JSON-encoded array in the content table. If I have an element that uses this field, is there a way I can just get that JSON-encoded value as an array in PHP? Any time I try to get the value of the field, I'm getting the entire MultiOptionsFieldData object which isn't desired in this case. I just want that array of checked values that's stored in the corresponding content table column.</p>

<p><a href="https://i.sstatic.net/euSJ1.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/euSJ1.png" alt="enter image description here"></a></p>

<p>I don't want to write any loops. I just want access to that actual column value from my element in PHP.</p>

<p>I don't want to write any additional queries to get that column value either. Surely, there must be a way to get the actual field value for checkbox fields. Right?</p>

<modules><checkboxes>
How do I access the checkbox field column value as a PHP array?
# How do I access the checkbox field column value as a PHP array?

(Asked by: username_0 on 2019-07-29)

I have a checkbox field for dining cuisine types and I see that the checked options are stored as a JSON-encoded array in the content table. If I have an element that uses this field, is there a way I can just get that JSON-encoded value as an array in PHP? Any time I try to get the value of the field, I'm getting the entire MultiOptionsFieldData object which isn't desired in this case. I just want that array of checked values that's stored in the corresponding content table column.

[![enter image description here](https://i.sstatic.net/euSJ1.png)](https://i.sstatic.net/euSJ1.png)

I don't want to write any loops. I just want access to that actual column value from my element in PHP.

I don't want to write any additional queries to get that column value either. Surely, there must be a way to get the actual field value for checkbox fields. Right?

**Tags:** modules, checkboxes

---

## 2 answers

### Answer by username_1 on 2019-07-29. Score: 1 | Accepted answer

MultiOptionsFieldData extends PHP's ArrayObject class.
You could get the values from it by casting it to an array like so:
$results = (array)$mofd;

That would give you an array of OptionData classes.  If you really didn't want to loop through them, you could do something like:
$func = static function($ofd) {
    return $ofd->value;
};

$results = array_map($func, (array)$mofd);

> **Comments:**
> **username_0**: Yeah, getting the array of OptionData instances was as close as I got but I was hoping for just the array of string values. Thanks, Brad. I think a method to obtain the raw value on the MultiOptionsFieldData class might be helpful in situations like this. Maybe something like:  $entry->getFieldValue('diningCuisine')->rawValue()  

---

### Answer by username_0 on 2019-07-29. Score: 1

Another option for getting the string values as an array after typecasting the MultiOptionsFieldData object as an array:
$values = ArrayHelper::getColumn(ArrayHelper::toArray( (array) $entry->getFieldValue('diningCuisine') ), 'value');


---

