Home > Backend Development > PHP Tutorial > PHP uses json_decode to force json data to be converted into an array_PHP tutorial

PHP uses json_decode to force json data to be converted into an array_PHP tutorial

WBOY
Release: 2016-07-20 11:03:14
Original
1484 people have browsed it

A simple application example reference document for PHP to use json_decode to force json data to be converted into an array. We used var_dump(json_decode($str,true)); to convert json into the data we want. ​

The code is as follows Copy code
 代码如下 复制代码

$a['d'][]=1;
$a['d'][]=2;
echo $str=json_encode(array($a));
var_dump(json_decode($str));

$a['d'][]=1;

$a['d'][]=2;

echo $str=json_encode(array($a));
 代码如下 复制代码
array(1) {
  [0]=>
  object(stdClass)#1 (1) {
    ["d"]=>
    array(2) {
      [0]=>
      int(1)
      [1]=>
      int(2)
    }
  }
}
var_dump(json_decode($str));


Conversion code
 代码如下 复制代码

var_dump(json_decode($str,true));

array(1) {
  [0]=>
  array(1) {
    ["d"]=>
    array(2) {
      [0]=>
      int(1)
      [1]=>
      int(2)
    }
  }
}


See, this is an object placed in an array; Let’s force the json_decode result to be converted into an array - add the parameter

to the fourth line

The code is as follows Copy code
var_dump(json_decode($str,true));array(1) { [0]=> array(1) { ["d"]=> array(2) { [0]=> int(1) [1]=> int(2) } }
}
http://www.bkjia.com/PHPjc/445323.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445323.htmlTechArticleA PHP simple application example reference document that uses json_decode to force json data to be converted into an array. We used var_dump(json_decode ($str,true)); Convert json into the data we want...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template