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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:56:47+00:00 2026-06-15T08:56:47+00:00

I am trying to retain only certain keys, and remove the rest from an

  • 0

I am trying to retain only certain keys, and remove the rest from an external API. I have an array (http://pastebin.com/vU8T4y7h), “data” containing the objects:

foreach ($data as $media) {
    foreach (array_keys($media) as $media_key) {
        if ($media_key!=="created_time" && $media_key!=="likes" && $media_key!=="images" && $media_key!=="id") {
            unset($media[$media_key]);
        }
    }
}

In this case, I am trying to only keep the created_time, likes, images, and id keys, however, the above code isn’t working. Any ideas as to why? Any other elegant solutions to achieve the same thing?

  • 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-15T08:56:48+00:00Added an answer on June 15, 2026 at 8:56 am

    The reason this isn’t working is because you aren’t unsetting from the original $data object. You can fix it one of two ways. Either access by reference or update your unset to act on the original $data object instead.

    Using reference:

    foreach($data as &$media) {
    

    Unsetting from $data

    unset($data[$media][$media_key]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get the rememberMe() function to remember users and retain sessions for
trying to figure out why this is happening - I have an input text
I am trying to create a shell script that pulls a line from a
I'm trying to have a custom UIViewController class get popped to the navigation controller,
I am trying to set the background color of the page at yumdom.com to
I'm trying to build something that will only fire a command once per keyboard
I'm trying to make a simple menu bar only application on xcode 4. Everything
I'm trying to use TBXML's method: + (id)tbxmlWithURL:(NSURL*)aURL success:(TBXMLSuccessBlock)successBlock failure:(TBXMLFailureBlock)failureBlock; from the TBXML+HTML.h But
I'm trying to upload a linear file under http in streaming mode. The idea
I'm trying to make it so that a certain view contained in a window

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.