Merge color palettes

Append one unnamed palette to another and retain the order of both inputs.

First 0 1
Second 0
Merged 0 1 2
[#111827, #475569, #f8fafc]

Append the second sequence after the first

The merged palette contains all three colors in input order and receives a fresh zero-based numeric index.

Merge unnamed sequences

merge() returns a new unnamed palette. Both source palettes remain unchanged.

<?php

use PhpColor\Color\Palette\ColorPalette;

$dark = ColorPalette::parse(['#111827', '#475569']);
$light = ColorPalette::parse(['#f8fafc']);
$merged = $dark->merge($light);

foreach ($merged->toHex() as $index => $hex) {
    printf("%d %s\n", $index, $hex);
}

// 0 #111827
// 1 #475569
// 2 #f8fafc
use PhpColor\Color\Palette\ColorPalette; $dark = ColorPalette::parse(['#111827', '#475569']); $light = ColorPalette::parse(['#f8fafc']); $merged = $dark->merge($light); foreach ($merged->toHex() as $index => $hex) { printf("%d %s\n", $index, $hex); } // 0 #111827 // 1 #475569 // 2 #f8fafc

Named palettes require an explicit collision policy

ColorPalette::merge() rejects the operation when either input is named. PHPColor does not guess how duplicate semantic keys should resolve.

InputBoth palettes must be unnamed.
OrderFirst palette entries precede second palette entries.
IndexesThe merged sequence receives zero-based numeric indexes.
Named keysResolve collisions yourself before constructing a named palette.

Choose a next step

Combine ordered sequences without inventing a key policy