Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
207 views
in Technique[技术] by (71.8m points)

php - What is the best way of creating an array from different checkboxes and then serializing?

I want to create an array from the content provided in 3 different checkboxes. I am using WP Frontend in WordPress, to create a form that has different multiselect boxes for different categories.

For example:

Category 1: Tags: 45,78,97 Category 2: Numbers: 3,7,9 Category 3: Marks: 4,8,12

When Selected, I would like to create an array that would look like this:

Array
(
    [tags] => Array
        (
            [0] => Array
                (
                    [0] => 45
                    [1] => 78
                    [2] => 97
                )
        )
    [numbers] => Array
        (
            [0] => 3
        )
    [marks] => Array
        (
            [0] => 18
        )
)

Then I would like to serialize it, which would look like this:

a:3:{s:4:"tags";a:1:{i:0;a:3:{i:0;i:45;i:1;i:78;i:2;i:97;}}s:7:"numbers";a:1:{i:0;s:1:"3";}s:5:"marks";a:1:{i:0;s:1:"18";}}

Any advice on the best way of creating this would be massively appreciated.

Thanks


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Thanks for your reply, sorry that its vague, i shall try and explain this further.

The aim of this is for an extension for the WPLMS addon, that will create quiz/questions.

The Tags array contains quiz category id numbers, For example, Maths is 45, English is 78 etc. This is the only section that will be multiple choice.

The Numbers section is a variable to set the amount of questions the quiz will contain. This will be just an input number such as "1" or "5".

The Marks section again is just a variable which will determine how many points/marks the user will get upon a correct answer.

I know it is strange to have the numbers and marks as an array, but this is how WPLMS would like its data to be.

Thanks


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...