PHP生成json
2024-09-04 12:49:33
索引数组
<?php
//json_encode(数组/对象)
$color = array('red','blue','green');
echo json_encode($color); //["red","blue","green"]
?>
关联数组
<?php
$animal = array('east'=>'tiger','north'=>'wolf','south'=>'monkey');
echo json_encode($animal); //{"east":"tiger","north":"wolf","south":"monkey"}
?>
json数组
<?php
$file_arr = array();//保存文件名
$dir = dir("D:\\input");//目录
while($file = $dir->read()){//循环目录
global $file_arr; //全局
if($file !=".." && $file !="."){//判断不为返回上级
$file_arr[] = $file;
}
}
echo json_encode($file_arr); //["1.png","2.png"]
?>
json关联数组
<?php
$animal = array();
$animal['east'] = "tiger";
$animal['north'] = "wolf";
echo json_encode($animal); //{"east":"tiger","north":"wolf"}
?>
最新文章
- [Erlang 0123] Erlang EPMD
- Java集合之LinkedList
- C语言调用curl库抓取网页图片(转)
- KVM 介绍(7):使用 libvirt 做 QEMU/KVM 快照和 Nova 实例的快照 (Nova Instances Snapshot Libvirt)
- js常用正则表达式汇总
- Visual Studio 2015 Update 3 RC 候选预览版粗来了
- snowflake主键生成策略
- calling c++ from golang with swig--windows dll (三)
- pymysql的使用及sql注入
- Hibernate Search集与lucene分词查询
- JavaScrip 入门第一课
- nuxt框架Universal和Spa两种render mode的区别
- ES5-ES6-ES7_async函数
- str类型
- 评定星级的前端显示js
- async语法升级踩坑小记
- linux上传下载文件rz,sz
- Gogland使用 - 非常简单查看Go语言源代码全貌!
- 20165218 2017-2018-2 《Java程序设计》课程总结
- Ionic开发Hybrid App问题总结