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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:16:40+00:00 2026-05-16T02:16:40+00:00

I have this multidimensional array: Array ( [0] => Array ( [id] => 1

  • 0

I have this multidimensional array:

Array (
    [0] => Array ( 
        [id] => 1 
        [list_name] => List_Red
    ) 
    [1] => Array (
        [id] => 2
        [list_name] => List_Blue 
    )
)

…and i would like to create a new array containing only the [id]’s from it.

I would appreciate it alot if you guys could help me with that ^^

Thanks in advance.

  • 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-16T02:16:40+00:00Added an answer on May 16, 2026 at 2:16 am

    @fabrik Your solution indeed does work but it is also incorrect as PHP will throw a E_WARNING telling you that you’re appending to an array that did not yet exist. Always initialise your variables before you use them.

    $newList = array();
    foreach($myList as $listItem) {
        $newList[$listItem['id']] = $listItem['list_name'];
    }
    

    This is now a list of all your list_names in the following format.

    Array (
        1 => List_Red
        2 => List_Blue
    )
    

    Much easier for you to work with and you can now iterate over it like so..

    foreach($newList as $itemID => $itemName) {
        echo "Item ID: $itemID - Item Name: $itemName<br>";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an multidimensional array that looks like this: Array ( [0] => Array
I have a multi dimensional array, like this: array('name' => array('title'=>'Title','date'=>'Created')) I store it
Possible Duplicate: php multi-dimensional array remove duplicate I have an array like this: $a
I have a list of recipes obtained from a database that looks like this:
I have a multidimensional array converted to JSON data in this format. [[null,null,null,null,null,null],[null,null,null,1,1,null],[null,null,null,null,1,1],[null,null,null,null,null,null],[null,null,null,null,null,null]] I
I have a multi-dimensional array that looks like this: The base array is indexed
I would like to add arrays to a list or multidimensional array (not all
I have got a multidimensional array : [everything_list] => Array ( [follow] => Array
I have this array that populates a dropdown menu. The key is my database
I have a multidimensional array that contains a variable number of sub arrays. Each

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.