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 8955853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:38:51+00:00 2026-06-15T14:38:51+00:00

I tried to put check box array data into table with 3 columns. I

  • 0

I tried to put check box array data into table with 3 columns.

I have an array named $a which contains 26 data, from A to Z.

Then I have another array named $b which contains some data.

I want to create a 3-columns table with 26 check boxes with the data in array $a.

if the data is contained in $b, its checkbox will be checked otherwise it’s unchecked.

The following is my code. I have no idea how to format the loop so the checkboxes and table will show correctly. Please help.

<html>
<body>
<table>
<?php

$a = array("A", "B", "C", "D", "E","F","G","H","I","J","K","L","M","N","O","P","Q","R","s","T","U","V","W","X","Y","Z");
$b = array("A","C","G","L","O","P","R","X","Z");
$a_size=count($a);

$tr=$a_size/3;
$reminder=$a_size%3;

if ($reminder!=0)
{
$tr+=1;
}

for($i=0;$i<$tr;$i++)
{
echo "<tr>";
foreach ($b AS $c)
{
    for($j=0;$j<3;$j++)
    {
        if(in_array($c,$b)) 
        {
            echo "<td><input name=\"system[]\" type=\"checkbox\" value=\"$c\" CHECKED> $c </td>";
        } 
        else
        {
            echo "<td><input name=\"system[]\" type=\"checkbox\" value=\"$c\"> $c </td>";
        }
    }
}   
echo "</tr>";
}
?>
</table>                                                
</body>
</html>                                                     
  • 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-06-15T14:38:52+00:00Added an answer on June 15, 2026 at 2:38 pm

    I think you’re making it a little overcomplicated! Here’s how I would approach this situation:

    <?php
        $a = array("A", "B", "C", "D", "E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
        $b = array("A","C","G","L","O","P","R","X","Z");
    ?>
    <table>
        <?php foreach ($a as $k => $v) : ?>
        <tr>
            <td><?php echo $v; ?></td>
            <td><input type="checkbox" name="system[]" value="<?php echo $v; ?>" <?php if (in_array($v, $b)) echo 'checked'; ?> /></td>
            <!-- add as many td's here as you like -->
        </tr>
        <?php endforeach; ?>
    </table>
    

    Here’s an alternative way to “flip” the layout.

    <?php
        $a = array("A", "B", "C", "D", "E","F","G","H","I","J","K","L","M","N","O","P","Q","R","s","T","U","V","W","X","Y","Z");
        $b = array("A","C","G","L","O","P","R","X","Z");
    ?>
    <table>
        <?php for ($i = 0; $i < 3; $i++) : ?>
        <tr>
            <?php foreach($a as $k => $v) : ?>
            <td><?php echo $v; ?><input type="checkbox" name="system[]" value="<?php echo $v; ?>" <?php if (in_array($v, $b)) echo 'checked'; ?> /></td>
            <?php endforeach; ?>
        </tr>
        <?php endfor; ?>
    </table>
    

    After our discussion in chat I have the code you’re looking for:

    <table>
        <tr>
        <?php for($i = 1; $i < count($a); $i++) : $j = $i-1; ?>
            <td><?php echo $a[$j]; ?><input type="checkbox" name="system[]" value="<?php echo $a[$j]; ?>" <?php if (in_array($a[$j], $b)) echo 'checked'; ?> /></td>
            <?php if($i % 3 === 0) echo '</tr><tr>'; ?>
        <?php endfor; ?>
        </tr>
    </table>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've tried to put together a solution from similar questions but have failed miserably.
I have gridview in which i have check box control Like this image. Problem
I tried to put font styles and color in EXCEL XLS sheet generation from
Last night I tried to put together something that I have had working since
I have tried to put <a href=page2.hta>Go Page 2</a> inside a .hta file. However,
Today I encountered something strange: I tried to put a utility method into an
I tried earlier to use a for loop to put data in but became
I tried the following code tree. If I put the header file hello.h into
I have a newbie question, which I have tried to understand for the past
I'ma having an issue retrieving data from the table that I've created. It displays

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.