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

  • Home
  • SEARCH
  • 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 6187927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:08:32+00:00 2026-05-24T02:08:32+00:00

Populate php array into HTML table I have data in a php array (say,

  • 0

Populate php array into HTML table

I have data in a php array (say, $rows2) that gives the below output in key-value pairs.
I am trying to format this data into an HTML table:

0 => Month:
1 => 07/2011,
2 => 7-8
3 => / 1432 A.H
4 =>  
5 => Location:
6 => Plainfield,
7 => NJ,
8 => USA
9 => Calculation Method:
10 => Value 10
11 =>  
12 => Juristic Method:
13 => Standard 

I tried to use the below code to populate the table:

echo '<table border=1>';
while (list($key, $value) = each($rows2)) {

    echo $value2.$value;
        if($i%5 == 0){
            echo '<tr><td>'.$value2.'</td></tr>';

        }
        $value2='';
    $i++;
}
echo '</table>';

I get the below output:

--------------------------------------------------------
Month:      |   07/2011     |   7-8     |   1432 A.H
--------------------------------------------------------
Location:   |   Plainfield  |   NJ      |   USA
--------------------------------------------------------
Calculation |   ValueX      |  Juristic |   ValueY
Method:     |               |  Method:  |
--------------------------------------------------------

I am trying to split the last row into 2 rows and then colspan the second
to look like the below result.

--------------------------------------------------------
Month:      |   07/2011     |   7-8     |   1432 A.H
--------------------------------------------------------
Location:   |   Plainfield  |   NJ      |   USA
--------------------------------------------------------
Calculation |           ValueX      
Method:     |           
--------------------------------------------------------
Juristic    |           ValueY
Method:     |               
--------------------------------------------------------

Could someone please help? Thanks in advance.

  • 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-24T02:08:32+00:00Added an answer on May 24, 2026 at 2:08 am

    If the following things are true:

    1. The number of rows will always be the same
    2. The number of columns will always be the same

    Then you’re probably better off just inserting parts of the array right into the table, like so:

    <table>
    <tr>
        <td><?= $array[0]?></td>
        <td><?= $array[1]?></td>
        <td><?= $array[2]?></td>
        <td><?= $array[3]?></td>
    </tr>
    <tr>
        <td><?= $array[9]?></td>
        <td colspan='3'><?= $array[10]?></td>
    </tr>
    <tr>
        <td><?= $array[12]?></td>
        <td colspan='3'><?= $array[13]?></td>
    </tr>
    </table>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

PROBLEM I have a nested PHP array that I need to populate from flat
I have a PHP function that returns an array. This is the output of
I have a PHP page that queries a DB to populate a form for
I've got an associative array in php that I want to stick into a
What's the fastest way to populate an array with the numbers 1-100 in PHP?
I have a PHP web app that generates a somewhat complex report from our
I need to have my PHP extension return an array of objects, but I
I am getting return type as array from PHP. When i populate in my
Let's say I have a Posts table and a Comments table. I want my
I have my own hand-rolled PHP MVC framework for some projects that I'm working

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.