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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:28:10+00:00 2026-06-09T01:28:10+00:00

My array looks like here: array(2) { [highpriority]=> array(2) { [0]=> // 1st item

  • 0

My array looks like here:

array(2) {
  ["highpriority"]=>
  array(2) {
    [0]=> // 1st item
    array(2) {
      [0]=>
      string(14) "Do the laundry"
      [1]=>
      string(6) "Sunday"
    }
    [1]=> // 2nd item
    array(2) {
      [0]=>
      string(19) "Study for math exam"
      [1]=>
      string(6) "Monday"
    }
  }
  ["lowpriority"]=>
  array(2) {
    [0]=> // 3rd item
    array(2) {
      [0]=>
      string(15) "Get car cleaned"
      [1]=>
      string(9) "Next week"
    }
    [1]=>
    array(2) { // 4th item
      [0]=>
      string(33) "Buy The Amazing Spider-Man on DVD"
      [1]=>
      string(5) "Later"
    }
  }
}

I try to create function that returns the string of the item by taking the number of the item as input. As example, my function readItem($number) would return “Get car cleaned” if I give the input $number = 3. There is highpriority and lowpriority nodes but more will be added, like mediumpriority, toppriority and so forth… I am thinking removing the parents in the array (the highpriority and lowpriority node) I can use $array[$number] to read the item string, correct?

With array_shift(), only children of highpriority remained. How can I make it go through every parent? I found here some code but it relies on knowing the parent by name: remove "wrapping" array (remove parent, keep children). If it can help, the data to my array is read from CSV using code from nickb in my previous question: Grouping CSV input by columns.

I am sure the solution is trivial, but is there other way beside a foreach loop and adding children manually to a new array? 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-09T01:28:12+00:00Added an answer on June 9, 2026 at 1:28 am

    There you go:

    <?php
    
    $input = array(
        'high' => array(
            array('Do the laundry', 'Sunday'),
            array('Study math', 'Monday')
        ),
        'low' => array(
            array('Get car cleaned', 'Next Week')
        )
    );
    
    $output = array();
    array_walk_recursive($input, function($item, $key) use (&$output) {
        $index = count($output) - $key;
        $output[$index][] = $item;
    });
    
    $readItem = function($index) use ($output) {
        return $output[$index-1];
    };
    
    var_dump($readItem(3));
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Noob question here! I have an array with hashes that looks like this: arr
I have an array that looks like this (the full list is here ):
total noob here. I've an array which looks like: Array ( [15] => Array
i have an array which could look like this: $config[$name][$array]['key'] = 'value'; // here
My array looks like this: array( 0 => 'val', 2 => 'val', 3 =>
My Array looks like this: Array ( [Team] => Array ( [0] => Array
How can I eliminate duplicate in an array using PHP, array looks like below
I have an array which looks like this: $arr = ( [0]=>Int(2) [1]=>Array( ....)
I have an array which looks like this: $data = array( array('timestamp' => 1312776000,
I have an array that looks like this: [ Object actions: Array[2] comments: Object

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.