Skip to content
Advertisement

concatenate array values ​into string?

I have this array, is stored in a variable called $ data :

JavaScript

and i want to add to another variable to send to an API

JavaScript

but when i echo $body the result its like this:

JavaScript

how can I add the string to have an output like this:

JavaScript

thanks to all

Advertisement

Answer

If you’re using XML, it’s better to learn and use an XML document API like DOMDocument.

Then you can build out the document like the following, using json_encode to encode the payload array into JSON.

JavaScript

The resulting XML will look like:

JavaScript

Test online: https://3v4l.org/nUSm5

For multiple it would be some thing like: https://3v4l.org/FgrhN

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement