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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:09:53+00:00 2026-05-31T18:09:53+00:00

Does any on know how can I convert this $events = array( array(type =>

  • 0

Does any on know how can I convert this

$events = array(
array("type" => "off-site", "title" => "aaa", "nid" => "11"),
array("type" => "off-site", "title" => "bbb", "nid" => "22"),
array("type" => "installation", "title" => "ccc", "nid" => "33"),
array("type" => "opening", "title" => "ddd", "nid" => "44"),
array("type" => "opening", "title" => "eee", "nid" => "55"),
array("type" => "opening", "title" => "fff", "nid" => "66")
);

into this

$events_processed = array(
"off-site" => array(
        array(
            "title" => "aaa",
            "nid" => "11"
        ),
        array(
            "title" => "bbb",
            "nid" => "22"
        )
),
"installation" => array(
        array(
            "title" => "ccc",
            "nid" => "33"
        )
),
"opening" => array(
        array(
            "title" => "ddd",
            "nid" => "44"
        ),
        array(
            "title" => "eee",
            "nid" => "55"
        ),
        array(
            "title" => "fff",
            "nid" => "66"
        )
)
);

using php?

I’ve already tried to apply different methods from different posts here but with no success.
I need the array to be nested so I can reorder the array by “type”.Hi

  • 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-31T18:09:55+00:00Added an answer on May 31, 2026 at 6:09 pm

    You can the code below, please note that your current output is not valid because you missed the array index …

    Example 1

        $events_processed = array();
        foreach($events as $options)
        {
            $events_processed[$options['type']][] = array("title"=>$options['title'],"nid"=>$options['nid']);
        }
        var_dump($events_processed);
    

    OR

    Example 2 (@dleiftah suggestion)

        $defautKey = "type" ; 
        foreach($events as $options)
        {
            $type = $options[$defautKey] ;
            unset($options[$defautKey]);
            $events_processed[$type][] = $options;
        }
         var_dump($events_processed);
    

    Both Result Would be Like this but number 2 is more flexible

            array
              'off-site' => 
                array
                  0 => 
                    array
                      'title' => string 'aaa' (length=3)
                      'nid' => string '11' (length=2)
                  1 => 
                    array
                      'title' => string 'bbb' (length=3)
                      'nid' => string '22' (length=2)
              'installation' => 
                array
                  0 => 
                    array
                      'title' => string 'ccc' (length=3)
                      'nid' => string '33' (length=2)
              'opening' => 
                array
                  0 => 
                    array
                      'title' => string 'ddd' (length=3)
                      'nid' => string '44' (length=2)
                  1 => 
                    array
                      'title' => string 'eee' (length=3)
                      'nid' => string '55' (length=2)
                  2 => 
                    array
                      'title' => string 'fff' (length=3)
                      'nid' => string '66' (length=2)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does any one know how can I convert a BSTR to an int in
Does any one know how can I cut the 1st 3 char in a
Does any body know how can I use MS_MPI in my VC++ MFC project?
Does any one know from where can I download source code for Cassini. I
Does any one know of a control that i can use with a ASP.Net
does any one know of any good countdown timer's for flash which i can
does anybody know any resources that I can refer to?
Does anyone know any good tool that I can use to perform stress tests
Does anyone know of any software that can be used to create Agile User
Does anyone know of any resources that can give me an idea of how

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.