Oihana PHP

resolveList.php

Table of Contents

Functions

resolveList()  : string|null
Resolves a list from a string or an array : - splits the string by the given separator - trims each element - removes empty elements - joins the list using the specified replacement - returns $default if the resulting list is empty

Functions

resolveList()

Resolves a list from a string or an array : - splits the string by the given separator - trims each element - removes empty elements - joins the list using the specified replacement - returns $default if the resulting list is empty

resolveList(string|array<string|int, mixed>|null $value[, string $separator = ';' ][, string $replace = PHP_EOL ][, string|null $default = null ]) : string|null
Parameters
$value : string|array<string|int, mixed>|null

Input value (string or array)

$separator : string = ';'

Separator for input string (default ';')

$replace : string = PHP_EOL

Separator for output string (default PHP_EOL)

$default : string|null = null

Default value if the result is empty

Tags
example
echo resolveList("a;b;c");
// Output:
// "a\nb\nc"

echo resolveList(";;;  ", ";", "\n", "fallback");
// Output:
// "fallback"

echo resolveList(["foo", "  bar  ", "", "baz"], ",", "\n");
// Output:
// "foo\nbar\nbaz"
Return values
string|null

Normalized string or default


        
On this page

Search results