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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:39:05+00:00 2026-06-11T05:39:05+00:00

Theoretical question that perhaps does not make any sense but still, maybe there is

  • 0

Theoretical question that perhaps does not make any sense but still, maybe there is a clever answer.

I want to iterate through array and get its keys and to something with them. A quick example of what I do:

foreach($array as $key => $value) {
    $other_array[$key] = 'something';
}

Now, PHP Mess Detector screams that $value is unused in this scope. Therefore I was thinking that perhaps this is not the best way to access keys of my array.

Any idea how to do it without unnecessarily taking out values out of my array? Does it have any significant performance impact … or perhaps I am just being paranoid and should carry on without wasting anyone’s time with stupid questions :).

  • 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-11T05:39:06+00:00Added an answer on June 11, 2026 at 5:39 am

    You could do something like this

    foreach(array_keys($array) as $key) {
     // do your stuff
    }
    

    That would make the foreach iterate over an array consisting of the keys from your array instead of the actual array. Note that it’s probably not better from a performance standpoint though.

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

Sidebar

Related Questions

More of a theoretical question, but wouldn't it make more sense to have only
This is a theoretical question, so expect that many details here are not computable
Note:I don't mean some theoretical question which don't have any implementation just languages that
A theoretical question, maybe it is obvious: Is it possible that an algorithm, after
This is purely theoretical question, I'm not doing anything, but I plan to. Is
I have a slightly theoretical question that I want to clear up before I
I have a rather theoretical question. My company has a working standard (documented) that
I have a very theoretical question: Is there a way to ban the use
I have been struggling to find an answer to this theoretical question, even tho
This is a theoretical question, I've already got a solution to my problem that

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.