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

  • Home
  • SEARCH
  • 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 8541245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:47:18+00:00 2026-06-11T11:47:18+00:00

This is my example array: $arrayy[0]=48.72; $arrayy[1]=21.32; $arrayy[2]=48.62; $arrayy[3]=21.31; $arrayy[4]=48.62; $arrayy[5]=21.31; This function function

  • 0

This is my example array:

$arrayy[0]=48.72;
$arrayy[1]=21.32;
$arrayy[2]=48.62;
$arrayy[3]=21.31;
$arrayy[4]=48.62;
$arrayy[5]=21.31;

This function

function writeDouble($array){
        for($curr = 0; $curr<count($array)-1; $curr++){
            echo $array[$curr]." - ";
            echo $array[$curr+1]."<br>";
            $curr++;
    }
}

should write a couples (0-1 , 2-3 , 4-5) – an output like:

48.72 - 21.32
48.62 - 21.31
48.62 - 21.31

What am I doing wrong, why do I got an error?

Notice: Undefined offset: 6 in C:\xampp\htdocs\xampp\lg\functions.php on line 466

Or could you define a better function to make couples? I can’t think anymore… 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-11T11:47:19+00:00Added an answer on June 11, 2026 at 11:47 am
    1. You’re using $array[$curr + 1] but you’re iterating from 0 to $curr - 1. You need an isset in case you have an odd number of values in your array.

    2. You’re incrementing 2 times (one time in your for, one time in the scope of your for).

    Code solution:

    $arrayy[0]=48.72;
    $arrayy[1]=21.32;
    $arrayy[2]=48.62;
    $arrayy[3]=21.31;
    $arrayy[4]=48.62;
    $arrayy[5]=21.31;    
    
    function writeDouble($array) {
            for ($curr = 0; $curr < (count($array) - 1); $curr += 2) {
                echo $array[$curr] . " - ";
                if (isset($array[$curr + 1])) {
                  echo $array[$curr + 1];
                }
                echo "<br>";
        }
    }
    
    writeDouble($arrayy);
    

    Output:

    48.72 - 21.32
    48.62 - 21.31
    48.62 - 21.31
    

    No more warning.

    • 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]
For example i have an array like this: $test= array(0 => 412, 1 =>
I have this example: var name; var id; var array = []; $.each(data, function(index,
Here is example how my array should look like: $library = array( 'book' =>
take this example: class Parent { public function __construct() { $this->config = array('a' =>
I'm attempting to create a search function, built something like this: function Search(array, key,
In this shortened example: print_r($foo); Array ( [0] => Array ( [function] => exception_handler
Do we have any array function in PHP to get this: Example: $array[0] =
How can I check an array recursively for empty content like this example: Array
I'm trying to isolate array name and array size from code. This example of

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.