如何使用 PHP 代码重新排列 JSON 文件

问题描述

我有一个这样的 json 文件

{
    "due this task": {"completed": true},"or maybe this one": {"completed": true},"this can wait": {"completed": true},"hey you": {"completed": false},"how is your day": {"completed": false}
}
  1. 我想根据表单上的按钮点击一次将“嘿你”这一行向上移动一行。

  2. 它需要在另一个 PHP 页面、javascript 或两者中完成,使用:json_decode(/READ THE FILE/),相应地重新排列数组,json_encode(/WRITE THE FILE/)

框架:

<?PHP
    $todos = json_decode(file_get_contents('todos.json'),true);

    foreach($todos as $todo)
    {
        //manipulate the array...
    }

    file_put_contents('todos.json',json_encode($todos,JSON_PRETTY_PRINT));
?>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)