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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:32:50+00:00 2026-06-10T07:32:50+00:00

I have this array: Array ( [0] => Array ( [id] => 70170b60a4 [name]

  • 0

I have this array:

Array
(
[0] => Array
    (
        [id] => 70170b60a4
        [name] => vip
    )

[1] => Array
    (
        [id] => 355a5f8cbd
        [name] => TEST LIST2
    )

[2] => Array
    (
        [id] => d1c2deef1d
        [name] => test list
    )

)

I call it $listInfo.

Now I want to take the info from this array and create a new one, that looks like this:

  Array
( 
 [70170b60a4] => vip
 [355a5f8cbd] => TEST LIST2
 [d1c2deef1d] => test list
)

I do this by:

foreach ($listinfo as $key) {
$list = array($key['id'] => $key['name'] );
}

Then I want to return the value (id) of vip:

$listId = array_search('vip', $list);

My problem is that the foreach loop does only create an array with the last values in the first array. so I get:

Array
(
     [d1c2deef1d] => test list
)

Can anyone tell me what I am doing wrong? I want all the values from the first array in there. Thanks a lot for any help.

  • 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-10T07:32:52+00:00Added an answer on June 10, 2026 at 7:32 am

    In your foreach loop, you’re creating a new array every time.

    Try this:

    $list = array();
    
    foreach ($listinfo as $key) {
        $list[$key['id']] = $key['name'];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this array the name of array is $list when i type this:
i have this array: [2] => Array ( [type] => jpg [name] => 25.jpg
I have this array of structures setup: <cfset table_columns = [ {name=Right Name, var_name=right_name,
I have this array of names (listedName) that I want to filter out and
I have this array: var myArray = [{'name': 'name1', 'desc': 'desc1'}, {'name':'name2', 'desc': 'desc2'},.....];
I have this array and I want to get both ID and Description from
I have this array: --- !map:ActiveSupport::HashWithIndifferentAccess search: !map:ActiveSupport::HashWithIndifferentAccess address: test I apply the following
I have this array $arr = array('test1', 'test', 'test3', 'var1', 'var5', 'var'); and I
I have this array lets call it array 1 Array ( [0] => Array
I have this array array(1) { [0]=> array(5) { [ppc_acc_name]=> string(9) Test test [ppc_acc_username]=>

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.