echo preg_replace_callback('~\[(.+?)\]~', fn($m) => $array[$m[1]] ?? $m[0], $message);
public class Test
{
public Test(params string[] elements) {
foreach(var element in elements)
AddElement(element);
}
private List<string> _elements = new List<string>();
public void AddElement(string x)
{
string AddElement = x;
_elements.Add(AddElement);
Console.WriteLine($"Элемент <{AddElement}> добавлен.");
Console.WriteLine($"Стэк: {String.Join("; ", _elements)}");
Console.WriteLine();
}
}
var x = new Test("a", "b", "c");
public class Test
{
private List<string> _elements = new List<string>();
// Для Collection Initializer нужен публичный метод Add
public void Add(string element) => AddElement(element);
public void AddElement(string x)
{
string AddElement = x;
_elements.Add(AddElement);
Console.WriteLine($"Элемент <{AddElement}> добавлен.");
Console.WriteLine($"Стэк: {String.Join("; ", _elements)}");
Console.WriteLine();
}
}
var x = new Test { "a", "b", "c" };