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

  • Home
  • SEARCH
  • 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 8419079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:30:42+00:00 2026-06-10T02:30:42+00:00

Assume I have the following array: $array( ’32’ => array(‘name’ => ‘paul’, ‘age’ =>

  • 0

Assume I have the following array:

$array(
  '32' => array('name' => 'paul', 'age' => 43),
  '17' => array('name' => 'eric', 'age' => 19),
  '99' => array('name' => 'dave', 'age' => 65)
)

I am only interested in the first $array item:

$array2 = array('key'=> 32, 'name' => 'paul', 'age' => 43)

What is the most efficient way to accomplish this? In other words, can I throw out all other items of $array with one command?

  • 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-10T02:30:44+00:00Added an answer on June 10, 2026 at 2:30 am

    Use array_shift().

    array_shift() shifts the first value of the array off and returns it,
    shortening the array by one element and moving everything down. All
    numerical array keys will be modified to start counting from zero
    while literal keys won’t be touched.

    $array2 = array_shift($array);
    

    This means that $array2 now holds the first element, while $array holds the rest of the elements.

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

Sidebar

Related Questions

Let us assume we have the following 2d array: 2 1 2 2 1
Let's assume I have the following multidimensional array (retrieved from MySQL or a service):
Assume I have an array of doubles that looks like the following: Array[10] =
lets assume I have the following array: a = {1; 'abc'; NaN} Now I
Background Assume I have the following nested variable in PHP. $data = Array( Array('lname'
In php, if you have the following code: $map = array( first => 1,
Lets assume we have the following array var arr = new string[] {foo,bar,jar,\r,a,b,c,\r,x,y,z,\r); Also
Assume that i have the following arrays containing: Array ( [0] => 099/3274-6974 [1]
First sorry for my English I have a problem with JSON. Assume the following
Assume I have the following arrays: N = 8 M = 4 a =

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.