首页 > Web开发 > 详细

php 重要函数归集

时间:2018-10-10 00:39:44      阅读:164      评论:0      收藏:0      [点我收藏+]

1、json_encode 与 json_decode

json_encode 把数组转化成字符串 json_encode(array)

json_decode 把目标字符串转成数组json_decode(string,true),如果省略第二个参数,那么生成的是个对象

<?php
header(‘Content-type:text/html;charset=utf8‘);
$arr = [
    ‘a‘ => ‘first‘,
    ‘b‘ => ‘second‘,
    ‘c‘ => ‘third‘,
    ‘d‘ => ‘fourth‘,
    ‘f‘ => ‘fifth‘,
    ‘e‘ => ‘sixth‘
];
$str = json_encode($arr);
var_dump($str);
//输出 string(75) "{"a":"first","b":"second","c":"third","d":"fourth","f":"fifth","e":"sixth"}"
var_dump(json_decode($str,true));
//输出 array(6) { ["a"]=> string(5) "first" ["b"]=> string(6) "second" ["c"]=> string(5) "third" ["d"]=> string(6) "fourth" ["f"]=> string(5) "fifth" ["e"]=> string(5) "sixth" }
//注意如果省略第二个参数,那么输出的是一个对象
?>

 

php 重要函数归集

原文:https://www.cnblogs.com/rickyctbu/p/9763913.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!