本篇文章给大家带来的内容是关于php如何生成json?php生成json的方法代码,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
索引数组
<?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()){//循环目录 if($file !=".." && $file !="."){//判断不为返回上级 $file_arr[] = $file; } }echo json_encode($file_arr); //["1.png","2.png"] ?>
相关推荐:
The above is the detailed content of How does php generate json? PHP method code to generate json. For more information, please follow other related articles on the PHP Chinese website!