How do I access the checkbox field column value as a PHP array?Checkbox array for days of the weekGet entries from client checked optionsIs it possible to convert plain text array to an unordered list?Searching on multiple checkboxesCraft 3 Custom Field Type with a File UploaderHow do I delete an asset with module or pluginCraft 3: Possible to merge checkbox and text values from a frontend form and put into a plaintext Craft field?How do I use a relation field in an element?What's the difference between `checkboxGroupField` and `checkboxSelectField` in Craft 3?Saving a SuperTable field within a Matrix Field

This day in history III

Dual-national, returning to US the day the US Passport expires; can he check in with airline on Dutch passport but reenter with expiring US passport?

Why do they sell Cat 5 Ethernet splitters if you can’t split the signal?

Dobbs Murder Mystery : A Picture worth 1000 words?

Are there any unpublished Iain M. Banks short stories?

Adopting a feral cat

Examples of simultaneous independent breakthroughs

What do I do with a party that is much stronger than their level?

Telling manager project isn't worth the effort?

Why is の所 used after ドア in this sentence?

Incrementing add under condition in pandas

Why does Canada require mandatory bilingualism in a lot of federal government posts?

If Trump gets impeached, how long would Pence be president?

Composing fill in the blanks

Finding the Maximum of a Continuous Function over a Closed Interval

Sci-fi change: Too much or Not enough

How many oliphaunts died in all of the Lord of the Rings battles?

Do the books ever say oliphaunts aren’t elephants?

Why does the Eurostar not show youth pricing?

Are the named pipe created by `mknod` and the FIFO created by `mkfifo` equivalent?

Why didn’t Christianity spread southwards from Ethiopia in the Middle Ages?

How could Nomadic scholars effectively memorize libraries worth of information

What is this 4 sharp symbol and what does it mean?

Copying an existing HTML page and use it, is that against any copyright law?



How do I access the checkbox field column value as a PHP array?


Checkbox array for days of the weekGet entries from client checked optionsIs it possible to convert plain text array to an unordered list?Searching on multiple checkboxesCraft 3 Custom Field Type with a File UploaderHow do I delete an asset with module or pluginCraft 3: Possible to merge checkbox and text values from a frontend form and put into a plaintext Craft field?How do I use a relation field in an element?What's the difference between `checkboxGroupField` and `checkboxSelectField` in Craft 3?Saving a SuperTable field within a Matrix Field






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















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



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?










share|improve this question






























    1















    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



    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?










    share|improve this question


























      1












      1








      1








      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



      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?










      share|improve this question














      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



      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?







      modules checkboxes






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 8 hours ago









      Benjamin KohlBenjamin Kohl

      2161 silver badge10 bronze badges




      2161 silver badge10 bronze badges























          2 Answers
          2






          active

          oldest

          votes


















          1














          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);





          share|improve this answer

























          • 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
            6 hours ago



















          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');





          share|improve this answer



























            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "563"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcraftcms.stackexchange.com%2fquestions%2f31101%2fhow-do-i-access-the-checkbox-field-column-value-as-a-php-array%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            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);





            share|improve this answer

























            • 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
              6 hours ago
















            1














            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);





            share|improve this answer

























            • 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
              6 hours ago














            1












            1








            1







            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);





            share|improve this 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);






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 7 hours ago









            Brad BellBrad Bell

            60.4k4 gold badges56 silver badges120 bronze badges




            60.4k4 gold badges56 silver badges120 bronze badges















            • 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
              6 hours ago


















            • 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
              6 hours ago

















            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
            6 hours ago






            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
            6 hours ago














            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');





            share|improve this answer





























              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');





              share|improve this answer



























                1












                1








                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');





                share|improve this answer













                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');






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 6 hours ago









                Benjamin KohlBenjamin Kohl

                2161 silver badge10 bronze badges




                2161 silver badge10 bronze badges






























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Craft CMS Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcraftcms.stackexchange.com%2fquestions%2f31101%2fhow-do-i-access-the-checkbox-field-column-value-as-a-php-array%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

                    Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

                    199年 目錄 大件事 到箇年出世嗰人 到箇年死嗰人 節慶、風俗習慣 導覽選單