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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:19:06+00:00 2026-05-15T20:19:06+00:00

Im iterating through two lists dumping data into their own single array, but i

  • 0

Im iterating through two lists dumping data into their own single array, but i need to merge the 2 arrays in numerical order into a single array.

Im using a counter (foreach and $i++) to name the keys in the proper order, but both operations leave me with arrays named with numbers 0-10.

How can i make a counter that will increment by only even or only odd numbers so i can merge the two lists after the fact and retain a proper numerical order?

ie, have the first loop name things 0-2-4-6-8-10, and the second loop count 1-3-5-7-9

  • 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-15T20:19:06+00:00Added an answer on May 15, 2026 at 8:19 pm

    Add 2 to the variable in the for loop instead of 1. $i++ only increments by 1. Try $i=$i+2.

    I don’t think that’s the only or best way to accomplish what you’re trying to do, though. How about putting the numbers into two arrays, without worrying about making the keys mesh like that, then making a new array out of the combination of the two, in order?

    $arr_one=array('a','c','e','g');
    $arr_two=array('b','d','f','h');
    
    $count=count($arr_one);
    $combined=array();
    for($i=0;$i<$count;$i++){
      $combined[]=$arr_one[$i];
      $combined[]=$arr_two[$i];
      }
    

    $combined is now array ( 0 => 'a', 1 => 'b', 2 => 'c', 3 => 'd', 4 => 'e', 5 => 'f', 6 => 'g', 7 => 'h' )

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

Sidebar

Related Questions

I am currently iterating through a loop and redimensionalising my array every time I
I am iterating through a JSON object and I am getting the data and
I wish to construct a list of anonymous types constructed by iterating through two
I am iterating through a List of custom data objects and outputing the data
I have two data tables which have a primary key column in common but
I am iterating through a list of certain objects (each object has two attributes
I am new to Java and especially to iterating through lists and modifying it's
I can certainly do this by iterating through results with PHP, but just wanted
I have two lists of strings that are passed into a function. They are
When iterating through a set of assemblies, e.g. AppDomain.CurrentDomain.GetAssemblies(), dynamic assemblies will throw 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.