中文字幕日韩精品一区二区免费_精品一区二区三区国产精品无卡在_国精品无码专区一区二区三区_国产αv三级中文在线

PHP如何將數(shù)組轉(zhuǎn)換成JSON?

PHP如何將數(shù)組轉(zhuǎn)換成JSON?

讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對這個(gè)行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長期合作伙伴,公司提供的服務(wù)項(xiàng)目有:域名與空間、虛擬空間、營銷軟件、網(wǎng)站建設(shè)、公安網(wǎng)站維護(hù)、網(wǎng)站推廣。

在PHP中可以通過使用函數(shù)“json_encode()”將數(shù)組轉(zhuǎn)為JSON,該函數(shù)的作用是對變量進(jìn)行JSON編碼,函數(shù)語法為“json_encode($val)”,返回值為JSON編碼的字符串。

使用示例

<?php
$a = array('<foo>',"'bar'",'"baz"','&blong&', "\\xc3\\xa9");

echo "Normal: ",  json_encode($a), "\\n";
echo "Tags: ",    json_encode($a, JSON_HEX_TAG), "\\n";
echo "Apos: ",    json_encode($a, JSON_HEX_APOS), "\\n";
echo "Quot: ",    json_encode($a, JSON_HEX_QUOT), "\\n";
echo "Amp: ",     json_encode($a, JSON_HEX_AMP), "\\n";
echo "Unicode: ", json_encode($a, JSON_UNESCAPED_UNICODE), "\\n";
echo "All: ",     json_encode($a, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE), "\\n\\n";

$b = array();

echo "Empty array output as array: ", json_encode($b), "\\n";
echo "Empty array output as object: ", json_encode($b, JSON_FORCE_OBJECT), "\\n\\n";

$c = array(array(1,2,3));

echo "Non-associative array output as array: ", json_encode($c), "\\n";
echo "Non-associative array output as object: ", json_encode($c, JSON_FORCE_OBJECT), "\\n\\n";

$d = array('foo' => 'bar', 'baz' => 'long');

echo "Associative array always output as object: ", json_encode($d), "\\n";
echo "Associative array always output as object: ", json_encode($d, JSON_FORCE_OBJECT), "\\n\\n";
?>
以上例程會輸出:
Normal: ["<foo>","'bar'","\\"baz\\"","&blong&","\\u00e9"]
Tags: ["\\u003Cfoo\\u003E","'bar'","\\"baz\\"","&blong&","\\u00e9"]
Apos: ["<foo>","\\u0027bar\\u0027","\\"baz\\"","&blong&","\\u00e9"]
Quot: ["<foo>","'bar'","\\u0022baz\\u0022","&blong&","\\u00e9"]
Amp: ["<foo>","'bar'","\\"baz\\"","\\u0026blong\\u0026","\\u00e9"]
Unicode: ["<foo>","'bar'","\\"baz\\"","&blong&","é"]
All: ["\\u003Cfoo\\u003E","\\u0027bar\\u0027","\\u0022baz\\u0022","\\u0026blong\\u0026","é"]

Empty array output as array: []
Empty array output as object: {}

Non-associative array output as array: [[1,2,3]]
Non-associative array output as object: {"0":{"0":1,"1":2,"2":3}}

Associative array always output as object: {"foo":"bar","baz":"long"}
Associative array always output as object: {"foo":"bar","baz":"long"}


推薦教程:《PHP》

新聞名稱:PHP如何將數(shù)組轉(zhuǎn)換成JSON?
分享鏈接:http://m.rwnh.cn/article0/cgssoo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站策劃、自適應(yīng)網(wǎng)站、商城網(wǎng)站、ChatGPT、網(wǎng)站維護(hù)網(wǎng)站排名

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都seo排名網(wǎng)站優(yōu)化
福清市| 武夷山市| 壶关县| 吴忠市| 丹巴县| 久治县| 阿坝县| 鄯善县| 襄樊市| 黎平县| 鱼台县| 昌平区| 财经| 札达县| 周口市| 枣强县| 师宗县| 镇远县| 枣强县| 始兴县| 昌黎县| 巧家县| 静安区| 绥中县| 贞丰县| 资兴市| 永定县| 小金县| 田东县| 淮南市| 卓尼县| 台北市| 新田县| 灵石县| 凤山县| 红原县| 甘谷县| 正蓝旗| 博罗县| 昔阳县| 娱乐|