A
A
Andrej Kopp2020-05-17 22:26:26
PHP
Andrej Kopp, 2020-05-17 22:26:26

How to insert values ​​from an array into a string?

Hello. Please tell me how to insert values ​​from an array into a string?

Here is an example of what is needed:

Here I get an array

$keys = explode(",", $keywords);
$key = $keys['0'];


from the keys separated by commas

key1, key2, key3, key4, ...

Next, I get the description variable:

$description = $modx->resource->get('description');


in the format

Здесь начинается текст с ключом {$key} который должен отобразиться ещё и здесь {$key} , а после должен идти рандомный текст.


In general, the meaning is as follows, you need to get the keys from the array and insert them into a variable.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FanatPHP, 2020-05-17
@FanatPHP

This is a bad format.
Instead of {$key} it should be %s

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question