Skip to content
Advertisement

Convert each array value into json using php

I have a PHP code that dumps following array:

JavaScript

I want to extract each URL from above array and convert it to JSON. JSON might look like:

JavaScript

I don’t know how to convert it into JSON. Also the tricky thing here is, that not every time there would be 4 URLS in array. It might be 1 or 2 or even 5. How do I check that how many URL does array has and then convert it to JSON according to that.

Also I tried searching on stack overflow before putting it here, but I didn’t found one that checks and then convert it to JSON

Thanks!

Edit #1

Direct json_encode won’t work because PHP does not return values from json which has characters such as 0 1 2 3

Advertisement

Answer

This would do the trick:

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