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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:46:04+00:00 2026-05-31T10:46:04+00:00

Is it possible to create an array of colors with PHP? What I’m trying

  • 0

Is it possible to create an array of colors with PHP?

What I’m trying to do:

  1. Select a start and end color
  2. Choose an amount of “steps”
  3. Create an array of those colors blending together (as a gradient) with that amount of steps.

Example:

Start color: White
End color: Black
Steps: 3

Result:

  1. “white”,
  2. “gray”,
  3. “black”

Of course the colors would be in RGB/hex

Anyone with a solution on this?

  • 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-31T10:46:05+00:00Added an answer on May 31, 2026 at 10:46 am
     $greys=rainbow('000000','FFFFFF',3);
    
     function rainbow($start, $end, $steps)
     {
        $s=str_to_rgb($start);
        $e=str_to_rgb($end);
        $out=array();
        $r=(integer)($e['r'] - $s['r'])/$steps;
        $g=(integer)($e['g'] - $s['g'])/$steps;
        $b=(integer)($e['b'] - $s['b'])/$steps;
        for ($x=0; $x<$steps; $x++) {
           $out[]=rgb_to_str(
              $s['r']+(integer)($r * $x),
              $s['g']+(integer)($g * $x),
              $s['b']+(integer)($b * $x));
        }
        return $out;
     }
     function rgb_to_str($r, $g, $b)
     {
          return str_pad($r, 2, '0', STR_PAD_LEFT)
              .str_pad($g, 2, '0', STR_PAD_LEFT)
              .str_pad($b, 2, '0', STR_PAD_LEFT);
     }
     function str_to_rgb($str)
     {
        return array (
          'r'=>hexdec(substr($str, 0, 2)),
          'g'=>hexdec(substr($str, 3, 2)),
          'b'=>hexdec(substr($str, 5, 2))
        );
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: PHP : Create array for JSON I have an array like this
Is it possible to create a javascript array similar to PHP's method which allows
Is it even possible to create an array of bits with more than 100000000
Is it possible to create a java representation of a package-level oracle associative array.
Is it possible to create images with PHP (as opposed to simply linking to
In Delphi, it is possible to create an array of the type var Arr:
Is it possible to create a new array in windows workflow? More specifically, in
Is it possible to create a dynamic array using something like this and store
Is it possible to create an .npy file without allocating the corresponding array in
I would like to know how, if possible, to create a n amount 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.