Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 494125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:28:07+00:00 2026-05-13T05:28:07+00:00

When a form gets posted, I get some checkbox values like the below: Array

  • 0

When a form gets posted, I get some checkbox values like the below:

Array ( [chk0] => true ,
        [chk1] => true,
        [chk3] => true,
        [chk1002] => on,
        [chk1005] => on 
      ) 

Using PHP,How can I construct a JSON request like this by using the above variables?

        "data":
        [
            {
                "checkboxval": true,
                "id": 0
            },
            {
                "checkboxval": true,
                "id": 1
            },
            {
                "checkboxval": true,
                "id": 3
            },
            {
                "checkboxval": true,
                "id": 1002
            },
            {
                "checkboxval": true,
                "id": 1005
            }
        ]

Please note that my POST variables can have other form variables too, but all checkbox values will be named with the prefix “chk”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T05:28:07+00:00Added an answer on May 13, 2026 at 5:28 am
    $output = array();
    foreach ($input as $k => $v) {
      $output[] = array(
        'checkboxval' => !!$v,
        'id' => preg_replace('!^chk!', '', $k),
      );
    }
    header('Content-Type: application/json');
    echo json_encode(array('data' => $output));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

All, When a form gets posted, I get some checkbox values like the below:
Ok I am trying to get the users First Name the form gets their
I have a form that sometimes gets linked to with some query string parameters.
Pls check code .html form gets submitted even if javascript returns false. <form id=form1
I have a basic HTML form that gets inserted into a server side div
We have a web application that is based around a form that gets passed
I am currently trying to write functional tests for a charging form which gets
I have a Ruby DateTime which gets filled from a form. Additionally I have
So an InfoPath form is deployed to a SharePoint server. It gets deployed through
I have a html page with a form. The form has Div which gets

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.