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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:40:19+00:00 2026-05-23T03:40:19+00:00

I have the following array (via var_dump ) $results : array(4) { [0]=> array(5)

  • 0

I have the following array (via var_dump) $results:

array(4) { 
    [0]=> array(5) { 
        [0]=> array(1) { ["evtId"]=> string(1) "2" } 
        [1]=> array(1) { ["evtId"]=> string(1) "3" } 
        [2]=> array(1) { ["evtId"]=> string(1) "4" } 
        [3]=> array(1) { ["evtId"]=> string(1) "5" } 
        [4]=> array(1) { ["evtId"]=> string(1) "6" } 
    [1]=> array(5) { 
        [0]=> array(1) { ["evtLocation"]=> string(2) "11 St Paul" } 
        [1]=> array(1) { ["evtLocation"]=> string(5) "12412 Horace St" } 
        [2]=> array(1) { ["evtLocation"]=> string(14) "Friends Center" } 
        [3]=> array(1) { ["evtLocation"]=> string(14) "Friends Center" } 
        [4]=> array(1) { ["evtLocation"]=> string(14) "Friends Center" } 
    [2]=> array(5) { 
        [0]=> array(1) { ["evtDate"]=> string(1) "11/12/2011" } 
        [1]=> array(1) { ["evtDate"]=> string(1) "06/05/2012" } 
        [2]=> array(1) { ["evtDate"]=> string(1) "10/10/2010" } 
        [3]=> array(1) { ["evtDate"]=> string(1) "06/06/2012" } 
        [4]=> array(1) { ["evtDate"]=> string(1) "10/12/2012" } 
    [3]=> array(5) { 
        [0]=> array(1) { ["evtType"]=> string(4) "Fun" } 
        [1]=> array(1) { ["evtType"]=> string(6) "Random" } 
        [2]=> array(1) { ["evtType"]=> string(9) "Childcare" } 
        [3]=> array(1) { ["evtType"]=> string(9) "Childcare" } 
        [4]=> array(1) { ["evtType"]=> string(9) "Childcare" } 

I’m using this array to pull database information into a function that builds a table. However, I need this to end up in the following format:

$rows[] = array('2', '11 St Paul', '11/12/2011', 'Fun'); 

I’ve really only been able to get this far:

foreach ($events as $field_arr) {
  //this gives me 4 arrays, each array containing all of the records for one field type.
}

Now I need to loop through each of the four arrays, take one value from the same index and add it to the $rows[] array, which I can pass to the table building function. I’ve tried variations of the following (inside the initial foreach loop)

 $x = count($result[0]); //this gives the number of fields
 for ($i = 0; $i < $x; $i++) {
    rows[$i] = $field_array[$i];
 }

I’ve been trying variations for half the day, with little luck (I’m ending up with arrays containing 4 times as many elements as I need, and having a hard time getting rid of the final array keys (['evtType'] etc).
If anyone can help point me in the right direction I’d greatly appreciate it.

  • 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-23T03:40:20+00:00Added an answer on May 23, 2026 at 3:40 am

    Most code posted here seems quite verbose, so here’s a short version:

    $rows = array();
    foreach ($results as $pairs)
    {
        foreach ($pairs as $rowNumber => $pair)
        {
            // current($pair) will give you the value
            // you could use key($pair) to get the key too
            $rows[$rowNumber][] = current($pair);
        }
    }
    

    That’s pretty much it. Each element of $results holds a list of key=>value pairs and we’re only interested in the value of each pair. The index of the pair is the index of the row, which we store in $rowNumber. I’ve run it and it seems to produce the expected results.

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

Sidebar

Related Questions

I have written a KornShell (ksh) script that sets an array the following way:
I have a column array with the following values in my sheet: 11, 15,
I have an associative array (object) of the following construction var menu = new
I have following string String str = replace :) :) with some other string;
I have following foreach-loop: using System.IO; //... if (Directory.Exists(path)) { foreach(string strFile in Directory.GetFiles(path,
I have following table structure: Table: Plant PlantID: Primary Key PlantName: String Table: Party
Now here's a fun problem. I have an object array as the following: objRequests
If I have the following: [HttpPost] public ActionResult DeclineClaims(String button, String[] Decline) { if
I have the following arrays in PHP (okay they are a bit bigger but
I have following situation: I have loged user, standard authentication with DB table $authAdapter

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.