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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:23:30+00:00 2026-06-03T15:23:30+00:00

I have a PHP array. array 0 => int 1 1 => int 13

  • 0

I have a PHP array.

array
  0 => int 1
  1 => int 13
  2 => int 16
  3 => int 17
  4 => int 18

What I want returned is a new array like this:

array(1, 13, 16, 17, 18)

ie. The values are now keys of a new array

I’ve tried array_flip, but I need to drop the values.
I’ve googled around and there doesn’t seem to anything that relates.

If someone could point me to the right direction or provide a better solution, it would be much appreciated.

EDIT:

array_flip returns:

array
  1 => int 0
  13 => int 1
  16 => int 2
  17 => int 3
  18 => int 4

What I want is just: array(1, 13, 16, 17, 18).

Am I understanding this wrong? Does the output I want actually have null values on each key?

  • 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-03T15:23:33+00:00Added an answer on June 3, 2026 at 3:23 pm

    You seem to not understand how arrays work. Every array that contains at least one value always has a key(s) and a value(s). In the case of this:

    array(1, 13, 16, 17, 18)
    

    the values are 1,13,16,… and the keys are implicitly set by PHP. In this case the value 1 has a key 0, value 13 has a key 1 and so on.

    The only difference between your first and second array is that in the first you have keys defined explicitly. In short, the arrays are identical.

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

Sidebar

Related Questions

I have a PHP array which looks like this example: $array[0][0] = 'apples'; $array[0][1]
I have a PHP array that looks like this: Array{ [0] { 'id' =>
I have a PHP array, say, $array = Array(Name1,Name2,Name3,Name4,Name5); I want to find the
I have a PHP 2D array, many keys, each with one value, I need
I have this array in PHP: array( [0] => array( 'username' => 'user1' )
I have the following serialized PHP array stored in a mySQL database: a:2:{i:2070;s:4:0.00;i:1901;s:4:1.00;} Now,
I have two arrays in php and I need to make a new array
I have been trying to figure this out, but couldn't. On php a multidimensional
i want to output an array containing numbers. I'm creating the array like this
I have wondered for a while now how to this. If I want to

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.