码迷,mamicode.com
首页 > Web开发 > 详细

php 重要函数归集

时间:2018-10-10 01:08:14      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:style   ext   set   目标   code   head   转化   生成   div   

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 重要函数归集

标签:style   ext   set   目标   code   head   转化   生成   div   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!