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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:46:51+00:00 2026-06-03T09:46:51+00:00

i want to take an array and cut some of the keys from it

  • 0

i want to take an array and cut some of the keys from it (not in order) and create a new array from them.

I have doing it using the array_shift() function, but came to a point where the next key needed to be skipped and then do the array_shift again.

How can I logically tackle this?

my array

Array
(
    [api] => Array
        (
            [0] => system
            [1] => assets
            [2] => theme
            [3] => resources
            [4] => api
            [5] => xml
            [6] => json
            [7] => jsonp
            [8] => request
        )

    [class] => Array
        (
            [name] => authentication
            [abbr] => auth
        )

    [directories] => Array
        (
            [application] => application
            [mvc] => Array
                (
                    [model] => model
                    [view] => view
                    [controller] => controller
                )

            [assets] => Array
                (
                    [folder] => assets
                    [css] => css
                    [img] => img
                    [js] => js
                )

            [config] => config
        )

    [smarty] => Array
        (
            [security] => on
            [delimiter] => Array
                (
                    [left] => {!
                    [right] => !}
                )

            [template] => Array
                (
                    [header] => header
                    [footer] => footer
                    [extension] => tpl
                )

        )

    [version] => Array
        (
            [component] => Array
                (
                    [0] => Array
                        (
                            [name] => CMS
                            [version] => 1.0
                        )

                    [1] => Array
                        (
                            [name] => TinyMCE jQuery Package
                            [version] => 3.5
                        )

                    [2] => Array
                        (
                            [name] => jQuery
                            [version] => 1.7.2
                        )

                )

            )
)

I need to make a new array from they keys: api, class, version

  • 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-03T09:46:52+00:00Added an answer on June 3, 2026 at 9:46 am

    Create an explicit list of keys that you’d like to move from one array to another. Cycle over that list, pulling from one and adding to another. Then remove the old copy from the original array:

    // Original Array, and empty Array
    $array = array( 'api' => 1, 'class' => 2, 'fizz' => 3, 'buzz' => 4 );
    $newAr = array();
    
    // For each key we'd like to keep
    foreach ( array( 'api', 'class' ) as $key ) {
      // (Re)move the value from the original array to our new array
      $newAr[$key] = $array[$key]; unset( $array[$key] );
    }
    
    // Show the contents of the new array
    print_r( $newAr );
    

    Try it online now: http://codepad.org/7iYG4iVB

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

Sidebar

Related Questions

I want to take some indices from the elements of a numpy.array. This is
I have been experimenting with using UUIDs as database keys. I want to take
What if I want to take user input from the args[0] array, but just
I want to take input from a textfield and turn it into an array
I have X , a three-dimensional array in R. I want to take a
I want to take 4 Bytes from Source : Array[0..500] of Byte; where c
how take string from array define as new array, how to code in php
How will I create a function to take an array of tweets from twitter
Say I have an array of size 5. I want to take an index
Hi i have float array in server side i want to take this array

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.