I have a string (in PHP) representing a JS array, and for testing purpose would like to convert it to a PHP array to feed them into a unit test. Here’s an example string
{ name: 'unique_name',fof: -1,range: '1',aoe: ',0,0,fp: '99,desc: 'testing ability,image: 'dummy.jpg'}
I could use a explode on the “,” then on the colon, but that is rather inelegant. Is there a better way?
This will return an object, with properties corresponding to the javascript array’s properties. If you want an associative array, pass true as a second parameter to json_decode
There is also a json_encode function for going the other way.