了解php数据转json格式与前端交互基础

时间:2022-08-11 22:39:02

php数据转json格式与前端交互

ArryJson1.php

<?php
$test=array(); $word=array("我12","要43","把23","你65","们7","全87","都","吃","掉79","嗯78","啊09","蒙67","多64","想54","去34","哪13","就54","去13","哪21");//循环数 for($b=0;$b<8;$b++){ //通过循环插入数组中
$suiji="";//定义一个随机值
$suijilength=3;//随机值的长度
for($a=0;$a<$suijilength;$a++){ //循环定义随机值
$c=rand(0,18); //随机获取0~18的随机数 这个值根据循环字长度而定
$suiji= $suiji.$word[$c]; //随机值=随机值+随机循环数
}
$test[$b]=$suiji;
}
$json=json_encode($test);//转换成json
// var_dump($json);
?>

ArryJson2.php

<?php
include("ArryJson1.php"); $new_j=json_decode($json);//将json解析为对象 for($a=0;$a<count($new_j);$a++){ echo "<br/>";
echo $new_j[$a];
}

每天努力一点,离梦想更近一些!

了解php数据转json格式与前端交互基础