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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:27:27+00:00 2026-05-24T23:27:27+00:00

I have two arrays, $country and $redirect with each entry corresponding with it’s exact

  • 0

I have two arrays, $country and $redirect with each entry corresponding with it’s exact counterpart e.g. $redirect[1] and $country[1].

After un-setting values throughout the array, I might be left with, for example, an array where only $var[4] and $var[2] are set. I want to re-assign array keys from 0 upwards, so that $var[2] would have it’s key re-assigned to $var[0] and $var[4] re-assigned to $var[1].

Essentially the sort() function, but sorting by current array key, as oppose to the numeric/string value of an array.

Is this possible?

Any answers or advice would be greatly appreciated ;)!

UPDATE:

I’ve attempted to use both ksort() and array_values(), however I’m not sure they’re really what I need, as I plan on using the size_of() function.

My code:

$var = array(2 => "value_1", 4 => "value_2", 6 => "value_3");
ksort($var);
for($i = 0, $size = sizeof($var); $i < $size; $i++) {
    $var[$i] = "foo";
}
var_dump($var);

Returns:

array(5) { [2]=> string(3) "foo" [4]=> string(7) "value_2" [6]=> string(7) "value_3" [0]=> string(3) "foo" [1]=> string(3) "foo" }

Any additional ideas/answers on how I could get this to work would be greatly appreciated!

  • 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-05-24T23:27:28+00:00Added an answer on May 24, 2026 at 11:27 pm

    Use array_values() (returns “sorted” array):

    $var = array(2 => "value_1", 4 => "value_2", 6 => "value_3");
    $var = array_values($var);
    for($i = 0, $size = sizeof($var); $i < $size; $i++) {
        $var[$i] = "foo";
    }
    var_dump($var);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two arrays. In each array I have objects with lots of properties
I have two arrays containing different keys and values. However, some keys store strings
I have two arrays values and keys both of the same length. I want
I have two arrays. Each is being pulled from MySQL via the following; $query
I have two arrays, one of the arrays holds all the unique values of
I have two arrays with anywhere from 1 to 5 set values. I want
I have two arrays of animations, one a before animation and one an after
I have two arrays: 1. each object here is a row retrived from database.
I have two arrays, I want to merge these two arrays into single array.
I have two arrays: $array1 = array('[param1]' ,'demo' ,'[param2]' ,'some' ,'[param3]'); $array2 = array('value1'

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.