John Davidson

How to convert String Array to php Array?

0 comments
Message:


How to convert Sting Array to PHP Array?


"['a'=>'value one','key2'=>'value two']"


to


$data=['a'=>'value one','key2'=>'value two'];


Please let me know if anyone knows of any solution




I want to take array input via textarea. And I want to convert that to a PHP array.


When I'm through textarea


['a'=>'value one','key2'=>'value two']


This is happening after submitting the from


"['a'=>'value one','key2'=>'value two']"


Now how do I convert from this to PHP Array?



My Answer:
To convert a String Array to a PHP Array, you can use the `explode()` function in PHP. Here's an example:

php
$stringArray = "apple,banana,orange";
$phpArray = explode(",", $stringArray);

print_r($phpArray);


This will output:


Array
(
[0] => apple
[1] => banana
[2] => orange
)


In this example, the `explode()` function splits the string by the delimiter (in this case, a comma) and creates an array with each element.

Rate this post

3 of 5 based on 8534 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us