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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:47:49+00:00 2026-06-07T07:47:49+00:00

$bar contains 4 (in this example, but potentially much more than 4) values I

  • 0

$bar contains 4 (in this example, but potentially much more than 4) values I want to copy into $foo and $blah in this way:

$foo[0] = $bar[0];
$foo[1] = $bar[2];
$blah[0] = $bar[1];
$blah[1] = $bar[3];

So, the even rows of $bar will be copied into $foo[i], and the odd rows will be copied into $blah[i].

I tried with:

for($i=0; $i<2; $i++)
{
    for($j=0; $j<4; $j++)
    {  
        if($j % 2 == 0)
            {  
            $foo[$i] = $bar[$j]; // EVEN
            }
            else
            {
            $blah[$i] = $bar[$j];  // ODD
        }
    }
}

However if I show the output of $foo and $blah, $foo[0] is equal to $foo[1], and $blah[0] is equal to $blah[1], while they should contain different values.

Example:
Source:

$bar[0]: 27.8
$bar[1]: Napoli-Posillipo
$bar[2]: 29
$bar[3]: Stadio San Paolo di Napoli, Napoli

(wrong) result of the loop:

$foo[0] = 29 (it should be 27.8)  
$foo[1] = 29
$blah[0] = Stadio San Paolo di Napoli, Napoli (it should be Napoli-Posillipo)
$blah[1] = Stadio San Paolo di Napoli, Napoli

Any hints?
Thanks

  • 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-07T07:47:51+00:00Added an answer on June 7, 2026 at 7:47 am

    you have made it to complex, something simple like this should work:

    foreach ($bar as $k=>$v){
        if($k % 2 == 0){  
             $foo[] = $v; // EVEN
        }else{
             $blah[] = $v;  // ODD
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

my mysql table contains an entry Foo Bar (i.e will potentially include capitals and
Hello I have a string which contains a mail address. For example ( user@foo.bar.com
So I am trying to import a module foo that contains directories bar and
Our site contains href links to various subdomains: foo.mysite.com, bar.mysite.com. For testing purposes, I'd
I have an entity class Foo foo that contains Collection<Bar> bars . I've tried
I'm trying to use GetPivotData to query Foo Bar values from a pivot table.
I'm so close to getting this effect perfect, but I have run into a
I have a string that contains something like this: ##### abc 'foo' /path/to/filename:1 #####
Is it possible to create a notification bar that contains multiple icons horizontally and
I am trying to print a report that contains a bar graph using the

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.