脑课堂编程教育

php数组转json

PHP 3年前
108 0 0
脑课堂编程培训

file

php数组转json字符串?使用函数:json_encode()

1、PHP数组转JSON格式字符串使用的函数:

file

2、示例演示,定义一个数组

<?php
    $arr =['red','yellow','blue'];
?>

3、将数组编码为json格式的字符串

<?php
    //定义一个数组
    $arr =['red','yellow','blue'];
    //为数组编码为json格式的字符串
    $jsonstr = json_encode($arr);
?>

4、输出编码后的json格式的字符串

<?php
    //定义一个数组
    $arr =['red','yellow','blue'];
    //为数组编码为json格式的字符串
    $jsonstr = json_encode($arr);
    //输出编码后的json格式的字符串
    echo $jsonstr;
?>

5、保存后,在浏览器查看输出的JSON格式的字符串

file

6、使用json_encode()的其他注意事项

file

收藏

本文标题:php数组转json

本文链接:https://naoketang.com/p/z0m74kj65gk6

评论区

推荐课程