How to usejson_decode() to Convert to an Array in PHP
The json_decode() function is a versatile and commonly used method to convert a JSON-formatted string into a PHP object.
PHP
<?php // Your JSON-formatted string $jsonString = '{"key1": "value1", "key2": "value2", "key3": "value3"}' ; // Convert JSON string to a PHP object $phpObject = json_decode( $jsonString ); // Output the result print_r( $phpObject ); ?> |
Output
stdClass Object ( [key1] => value1 [key2] => value2 [key3] => value3 )
How to Convert a String to JSON Object in PHP ?
Given a String, the task is to convert the given string into a JSON object in PHP. JSON (JavaScript Object Notation) is a widely used data interchange format. PHP provides convenient functions to work with JSON data.
Contact Us