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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:02:21+00:00 2026-05-23T11:02:21+00:00

$test = array(1, 2, 3, 4, 5); foreach($test as $element) { echo $element; $element

  • 0
$test = array(1, 2, 3, 4, 5);


foreach($test as $element)
{
    echo $element;        
    $element = next($test);         
    echo $element;
}

This produces the output “122334455” in PHP 5.2.0
The output “13243545” is produced in PHP 5.3.3

How do I reproduce the output of 5.2.0 in 5.3.3 most efficiently by means of controlling the iterator?

This may be a bug as the iterator works in 5.2 inside the foreach, but not in 5.3’s foreach.

  • 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-23T11:02:22+00:00Added an answer on May 23, 2026 at 11:02 am

    It seems a bug related with PHP. You can use a more explanatory “for” loop:

    $c = count($test);
    
    for($i=0; $i < $c; $i++) {
        echo $test[$i];
        if(isset($test[$i+1])) {
            echo $test[$i+1];
        } else {
            echo $test[$i];
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

function returnsAnArray () { return array ('test'); } echo returnsAnArray ()[0]; generates a syntax
<?PHP $signup_errors = array(); $signup_errors['captcha'] = 'test 1'; $signup_errors['something'] = 'test 2'; $signup_errors['another'] =
I have a string like this: TEST.DATA.Data.COR.Point,2;TEST.DATA.Data.COR.Point,5;TEST.DATA.Data.COR.Point,12;TEST.DATA.Data.COR.Point,12;TEST.DATA.Data.COR.WordTOFIND,18 I have a list of array with
PHP: <?php $menu = array( array('label' => 'myLabel', 'submenu' => array('label' => 'test label',
How can foreach loop affect session variable? session_start(); $_SESSION[test] = Session content; echo $_SESSION[test].'<br
Can jQuery test an array for the presence of an object (either as part
I have an array that looks like: $fields = array( f1 => array(test), f2
How do I keep a certain number of elements in an array? function test($var)
I create array: TextBox[] textarray = new TextBox[100]; Then in cycle set this params,
While optimizing a function in PHP, I changed if(is_array($obj)) foreach($obj as $key=>$value { [snip]

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.