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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:03:16+00:00 2026-06-03T10:03:16+00:00

I have a Multi dimension array and what i ‘d like to do is

  • 0

I have a Multi dimension array and what i ‘d like to do is put array to insert the element in each column

for example

Multi dimension array :

Tony 14
Peter 20

I would like to insert them into a different array , so that

column0[]={Tony, Peter}
column1[]={14, 20}

Since i do not know the actual no of column , how can i achieve this?

   for ($row = 1; $row <= $highestRow; $row++) {
        for ($y = 0; $y < $highestColumn; $y++) {
    ................what should be added here................
            }
        }

Thank you

  • 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-03T10:03:17+00:00Added an answer on June 3, 2026 at 10:03 am

    Check out the code below. All you’re doing in your actual loop, is swapping the $y and the $row

    <?php
    $original_array = array(
        array('Tony', 14),
        array('Peter', 20)
    );
    
    print_r($original_array);
    
    // Array
    // (
    //     [0] => Array
    //         (
    //             [0] => Tony
    //             [1] => 14
    //         )
    
    //     [1] => Array
    //         (
    //             [0] => Peter
    //             [1] => 20
    //         )
    
    // )
    
    $new_array = array();
    
    for ($row = 0; $row < count($original_array); $row++) {
        for ($y = 0; $y < count($original_array[0]); $y++) {
            $new_array[$y][$row] = $original_array[$row][$y];
        }
    }
    
    print_r($new_array);
    
    // Array
    // (
    //     [0] => Array
    //         (
    //             [0] => Tony
    //             [1] => Peter
    //         )
    
    //     [1] => Array
    //         (
    //             [0] => 14
    //             [1] => 20
    //         )
    
    // )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a multi-dimension array like: $fields = Array ( [1] => Array (
i have a multi dimension array with sub array having repeated values of '
I have a multi-dimensional array, which basically consists of one sub-array for each year.
I have a multi dimensional array, like this: array('name' => array('title'=>'Title','date'=>'Created')) I store it
If I have a multi dimensional array in PHP like so... [0] => Array
I was wandering if I have a multi-dimension array (M*N matrix), how to determine
i have multi dimensional array like below, Array ( [14289] => Array ( [0]
I have a multi-dimensional array with 4 entries in each value - (1st name,
Let say I have a multi-dimensional array like int a[10][10] int b[10][10] void arrayCopy(int*
I have a multi-dimensional array right now that looks like this: function art_appreciation_feeds() {

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.