美文网首页
PHP编程实战15-2

PHP编程实战15-2

作者: 海边拾贝 | 来源:发表于2015-11-09 16:41 被阅读0次
<!--PHP编程实战-->
<!--JSON & Ajax -->
<!--15-2-->
<!--将PHP嵌套数组编码为JSON格式,再解码为PHP数据类型-->
<?php
$books = array(
    array("author" => "Lewis Carroll",
        "title" => "Alice's Adventures in Wonderland",
        "year" => 1865),
    array("author" => "Yann Martel",
        "title" => "Life of Pi",
        "year" => 2001),
    array("author" => "Junot Diaz",
        "title" => "The Bried Wondours Life of Oscar Wao",
        "year" => 2007),
    array("author" => "JOseph Heller",
        "title" => "Catch-22",
        "year" => 1961),
    array("author" => "Timothy Findley",
        "title" => "Pilgrim",
        "year" => 1999),
    array("author" => "Fyodor Dostoyevsky",
        "title" => "Brothers Karamazov",
        "year" => 1880),
);
$json_books = json_encode($books);
$decoded_json_books = json_decode($json_books);
?>
<pre>
    <?php var_dump($json_books); ?>
    <?php var_dump($decoded_json_books) ?>
</pre>

相关文章

网友评论

      本文标题:PHP编程实战15-2

      本文链接:https://www.haomeiwen.com/subject/tvfhhttx.html