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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:24:02+00:00 2026-06-11T18:24:02+00:00

I have a PHP array which has several different fields. For some of the

  • 0

I have a PHP array which has several different fields. For some of the rows id and name is the same and the rest of data is different.

I want to display the data in an HTML table without listing the duplicated data more than once. I realize that I can use colspan/rowspan to merge the table cells, but I’m not sure how to do counts/sums based on the matching values.

Below is how my table looks like :

Id      Name     value1      value2       value3
2312     ABC     test        test2         test3   
2312     ABC     XYz          122           211
2455     XYZ     val11        val2          val3

Any help will be appreciated.

  • 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-11T18:24:03+00:00Added an answer on June 11, 2026 at 6:24 pm

    I can suggest you to create a new multidimensional array and merge the arrays that have the same ID … the rest will be easy. Take a look at the example I’ve made

    <?
     $init_array = array(
      array('id'=>2312, 'name'=>'ABC', 'value1'=>'asda', 'value2'=>'sdf', 'value3'=>'dfg'),
      array('id'=>2312, 'name'=>'ABC', 'value1'=>'asd', 'value2'=>'fgd', 'value3'=>'ret'),
      array('id'=>2455, 'name'=>'XYZ', 'value1'=>'sdgg', 'value2'=>'rew', 'value3'=>'gdg'),
     );
     $formatted_array = array();
    
     foreach( $init_array as $element ) {
      $formatted_array[ $element['id'] ][] = $element;
     }
    ?>
    
    <table border="2">
     <? foreach($formatted_array as $row ): ?>
       <tr>
         <td rowspan="<?=count($row)?>"><?=$row[0]['id']?></td>
         <td rowspan="<?=count($row)?>"><?=$row[0]['name']?></td>
         <? foreach( $row as $value ): ?>
          <td><?=$value['value1']?></td>
          <td><?=$value['value2']?></td>
          <td><?=$value['value3']?></td>
          </tr><tr>
         <? endforeach; ?>
       </tr>
     <? endforeach; ?>
    </table>
    

    the example in CodePad

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a php array that has a bunch of data that I need
I have an Array in PHP which contains data from database. And it prints
I have a php array containing the mysql values of checkboxes, which has been
I have some binary data which has a corresponding map file which identifies each
I have a config.php file which has some constants and methods. I have a
Hi just looking for some direction, I have a HTML form which has several
I am trying to validate Zend_Form which has several optional fields and I want
I have a PHP array which looks like this example: $array[0][0] = 'apples'; $array[0][1]
i have one php file which process adding of record in Database fro array.
I have a array stored in a PHP file in which I am storing

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.