Search by

26b / joiner

xipasduarte

Join strings with conditional values

Package info

github.com/26B/joiner

pkg:composer/26b/joiner

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-10-03 20:44 UTC

This package is auto-updated.

Last update: 2026-10-03 20:56:38 UTC


README

Join strings with conditions attached to values or array keys.

Installation

composer require 26b/joiner

Requires PHP 8.3 or later.

Usage

<?php

use function Joiner\join;

$name = 'Ada';
$isReturning = true;

$message = join(['Hello,', $name, ['welcome back' => $isReturning]], ' ');
// 'Hello, Ada welcome back'

join(args: ['first', 'second'], separator: ' / ');
// 'first / second'

Arguments

  • Pass all values in the first array argument; use the optional second argument to choose the separator (default: '').
  • Non-empty strings and integers are included as strings, including '0'.
  • Objects implementing __toString() are included using their string value.
  • List arrays are recursively processed; associative arrays and stdClass objects include keys/properties whose values pass their condition.
  • Other non-string values in lists are ignored. For map conditions, non-empty strings are true; other values use PHP truthiness.

Other objects are ignored; map objects must be stdClass.

CSS class names

classnames(...$arguments) joins values with spaces like join(), then emits a PHP E_USER_WARNING for each output token that is not a CSS <ident> according to MDN. It returns the joined string unchanged. Use join() when the strings are not CSS class names.

use function Joiner\classnames;

classnames('button', ['button-active' => true]);
// 'button button-active'