V
V
Vasya Surname2018-08-27 03:18:13
PHP
Vasya Surname, 2018-08-27 03:18:13

How to concatenate two json strings?

There are two lines like this

[
{"MIGX_id":"1","image":"1.gif","title":"бе"},
{"MIGX_id":"2","image":"dom_17.gif","title":"ме"}
]

[
{"MIGX_id":"1","image":"tes.gif","title":"yes"},
{"MIGX_id":"2","image":"ex.gif","title":"no"}
]

How to combine them like this?
[
{"MIGX_id":"1","image":"1.gif","title":"бе"},
{"MIGX_id":"2","image":"dom_17.gif","title":"ме"},
{"MIGX_id":"3","image":"tes.gif","title":"yes"},
{"MIGX_id":"4","image":"ex.gif","title":"no"}
]

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vyacheslav Barsukov, 2018-08-27
@slavabars

json_encode(array_merge(json_decode($a, true),json_decode($b, true)))

D
dollar, 2018-08-27
@dollar

1) Remove the characters [ ] from each line. The symbols will be at the edges, so you don't need to search. As a last resort, there are the strpos and substr functions.
2) Glue the lines using a comma as a separator
3) Glue the characters [ ] along the edges of the resulting line

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question