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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:18:14+00:00 2026-05-15T00:18:14+00:00

I am trying to create a function which maps a recurring pattern of integers

  • 0

I am trying to create a function which maps a recurring pattern of integers using an array.

As an example if I have a starting array of (0,1,3) and I know that I want to stop the pattern when I hit 15.

The pattern gets incremented by a fixed integer each time (lets say 4) so my final pattern should be..

0
1
3
4 (0 + 4)
5 (1 + 4)
7 (2 + 4)
8 (4 + 4)
9 (5 + 4)
11(7 + 4)
12(8 + 4)
13(9 + 4)
15(11+ 4)

Does anyone have any pointers on how this can be achieved?

My current implementation works but is stupidly inefficient which something like this…

$array = array(0,1,3);
$inc = 4;
$end = end($array);
$final = 15;

while($end < $final)
{
$tmp = array();
foreach($array AS $row)
{
$tmp = $row + $inc;
}
$array = merge($tmp, $array);
$end = end($array);
}
  • 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-15T00:18:15+00:00Added an answer on May 15, 2026 at 12:18 am

    I assume that you want to have all the new values in the same array.
    So:

    //original array
    $values =  array(0, 1, 3);
    
    //incremental value
    $inc = 4;
    //stop value
    $stop = 15;
    
    //set the index counter to the origin
    $curr_index = 0;
    
    //while the last value of the array is lower than the stop value
    while($values[end($values)] < $stop)
    {
        //calculate the new value
        $new_value = $values[$curr_index] + $inc;
        //add the new value to the array
        array_push($values, $new_value);
        //update the index counter
        $curr_index ++;
    }
    

    this code should work for any initial value in the array, any incremental value and any stop value.

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

Sidebar

Related Questions

I'm trying to create a popup for which I am using jQuery's CSS function.Here's
I'm trying to create map (using the Google Maps JavaScript API V3 ) which
I'm trying to create a function which takes an array as an argument, adds
I'm trying to create a function which can be called with a lambda that
I am trying to create a function which will give me alphabet position when
I am trying to create a function which will take arguments arg1, arg2... then
I am currently trying to create a function which will allow me to pass
I am trying to create a vimrc function which will clean up a line
I'm trying to create a simple function which returns me a date with a
I'm trying to create a function that would append two vectors together, but I

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.