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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:29:00+00:00 2026-05-23T10:29:00+00:00

Array mapping? I have $A= array(A1=>array(x=>1,b=>2,d=>3,s=>8), A2=>array(a=>4,b=>3,c=>2,d=>1) ); OUTPUT(HTML): | a | b |

  • 0

Array mapping?

I have

$A= array("A1"=>array("x"=>1,"b"=>2,"d"=>3,"s"=>8),
          "A2"=>array("a"=>4,"b"=>3,"c"=>2,"d"=>1)
          );

OUTPUT(HTML):

   | a |  b  |  c | d | x | s
------------------------------
A1 | 0 |  2  |  0 | 3 | 1 | 8
A2 | 4 |  3  |  2 | 1 | 0 | 0

Anyone know how to do this ?

  • 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-23T10:29:00+00:00Added an answer on May 23, 2026 at 10:29 am

    Retrieve the keys

    $keys = array_unique(array_merge (array_keys($A['A1']), array_keys($A['A2'])));
    

    Then create the output

    echo " | ";
    echo implode(' | ', $keys) . "\n";
    
    echo "\n";
    foreach ($A as $name => $oneA) {
      echo "$name ";
      foreach ($keys as $key) echo "| ". (isset($oneA[$key]) ? $oneA[$key] : 0);
      echo "\n";
    }
    

    or as html-table

    <table>
      <tr>
        <td>&nbsp;</td>
        <td><?php implode('</td><td>', $keys);</td>
      </tr>
      <?php foreach ($A as $name => $oneA) : ?>
      <tr>
        <td><?php echo $name; ?></td>
        <?php foreach ($keys as $key): ?>
          <td><?php echo isset($oneA[$key]) ? $oneA[$key] : 0; ?></td>
        <?php endforeach; ?>
      </tr>
      <?php endforeach; ?>
    </table>
    

    You may sort the keys before and format the output. Its just the short form.

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

Sidebar

Related Questions

This is in Squeak/Pharo. If I want to have a mapping between Character objects
I have an xml mapping file that looks something like this <colourMappings> <model name=modelX>
I have this domain model: class Person < ActiveRecord::Base composed_of :address, mapping: [%w(address_street street),
I have this mapping in my C# application string [,] unicode2Ascii = { {
I have a table mapping strings to numbers like this: t['a']=10 t['b']=2 t['c']=4 t['d']=11
I have an array of elements that I would like to apply a mapping
So I have the two array of size 256 like this: int arrayOne[] =
I have an array, whose size is 256. This array has elements which are
I'm trying to use empty() in array mapping in php. I'm getting errors that
Is there a way of mapping data collected on a stream or array to

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.