Сгенерировать массив сообщений [закрыто]

У меня есть шаблон сообщения

      "['Hello!','Hi!', 'Hi there!'] How are you? My name is ['Jason!','Alex!', 'Anthony!']"

Таких позиций может быть больше двух. Как программно получить все возможные варианты сообщения с помощью PHP?

Нравиться:

       ["Hello! How are you? My name is Jason!",
 "Hello! How are you? My name is Alex!",
 "Hello! How are you? My name is Anthony!",
 "Hi! How are you? My name is Jason!",
 "Hi! How are you? My name is Alex!",
 "Hi! How are you? My name is Anthony!",
 "Hi there! How are you? My name is Jason!",
 "Hi there! How are you? My name is Alex!",
 "Hi there! How are you? My name is Anthony!"]

1 ответ

      $hellos = ['Hello!', 'Hi!', 'Hi there!'];
$names = ['Jason!', 'Alex!', 'Anthony!'];

$res = [];
foreach ($hellos as $hello) {
    foreach ($names as $name) {
        $res[] = "$hello How are you? My name is $name";
    }
}
Другие вопросы по тегам