1、json_encode 与 json_decode
json_encode 把数组转化成字符串 json_encode(array)
json_decode 把目标字符串转成数组json_decode(string,true),如果省略第二个参数,那么生成的是个对象
<?phpheader(‘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