If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
json_decode() function ,JSON string को decode करता है।
json_decode ( string $json , bool|null $associative , int $depth , $json_constants);
string $json | required : value जिसे आप decode करना चाहते हैं।
bool|null $associative | oprional : यह Boolean value है , true pass करने पर हमें JSON objects as a Associative Array रेतुर्न होगा। और false pass करने पर JSON objects as a Object return होगा। By Default false होता है।
int $depth | optional : यह maximum depth specify करती है , जिसकी value 0 से ज्यादा ही होनी चाहिए।
$json_constants | optional : यह JSON Constants , जिसके according value JSON format में convert होती है। कुछ JSON Constants इस प्रकार हैं -
❕ JSON Contstans
JSON_FORCE_OBJECT, JSON_HEX_QUOT, JSON_HEX_TAG, JSON_HEX_AMP, JSON_HEX_APOS, JSON_INVALID_UTF8_IGNORE, JSON_INVALID_UTF8_SUBSTITUTE, JSON_NUMERIC_CHECK, JSON_PARTIAL_OUTPUT_ON_ERROR, JSON_PRESERVE_ZERO_FRACTION, JSON_PRETTY_PRINT, JSON_UNESCAPED_LINE_TERMINATORS, JSON_UNESCAPED_SLASHES, JSON_UNESCAPED_UNICODE, JSON_THROW_ON_ERROR.
Return Value : PHP value के type के according decoded value return होती है। और अगर pass की गयी value decode न हो पायी तो null return होता है।
File : php_json_decode.php
<?php
$json = '{
"course":"Computer Science",
"no_of_subject":4,
"subjects":"PHP , JavaScript , jQuery , AJAX"
}';
var_dump(json_decode($json));
/*now , pass true so that you can see difference*/
var_dump(json_decode($json, true));
?>
object(stdClass)#1 (3) { ["course"]=> string(16) "Computer Science" ["no_of_subject"]=> int(4) ["subjects"]=> string(32) "PHP , Javascript , jQuery , AJAX" } array(3) { ["course"]=> string(16) "Computer Science" ["no_of_subject"]=> int(4) ["subjects"]=> string(32) "PHP , Javascript , jQuery , AJAX" }
❕ Important
var_dump() function variable(s) के structure / information के बारे में बताता है। यह function variable में stored value उसका type , length etc. बताता है।
Learn More About var_dump()
Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)
Get connected with me. :) LinkedIn Twitter Instagram Facebook