How to convert JSON string to an array in PHP? Explain with example?

Posted by

we can convert JSON string to an array with the help of  json decode() function. This functon accepts the JSON string as the first parameter and a few additional parameters to control the process of converting JSON to PHP array.

we use the json decode() function to convert JSON string to an array in php.

JSON STRING TO ARRAY

example

<?php

	$json_string = '{"mp": "gwalior", "bhopal": "delhi", "mumbai": "gujrat"}';
			
	  echo "<pre>";
			
	print_r (json_decode($json_string));
			
	echo "</pre>";
			
			
?>

output

stdClass Object
(
    [mp] => gwalior
    [bhopal] => delhi
    [mumbai] => gujrat
)
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x