Skip to content
Advertisement

Explode a string to array with key => value

I have string is:

JavaScript

How Can I convert from $string to an array with key => value.

JavaScript

Updated:

@Mark Baker my php version is 5.4 so I cannot test your code, thanks

@Aleatoric I’m use this code, but the array return some space character on key and value:

JavaScript

I have use trim() to strips all space, but can you tell me best idea for this issue without use trim() function?

Advertisement

Answer

You’re going to have to explode the string first with:

JavaScript

and then iterate over the elements with a foreach loop to split the strings and put them into an associative array:

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