السلام عليكم
لدي مشكلة مع دالة unset استخدمها لازالة عنصر من ملف json ، المشكلة هي عندما استخدم الدالة بهذا الشكل
$file_data = json_decode(file_get_contents($file), true); $key = array_search($_POST['id'], array_column($file_data, 'id')); unset($file_data[$key]); file_put_contents($file, json_encode($file_data));
يتم تغيير شكل الداتا
من
[{"id": 1671308031, "rss_link": "aa", "website_name": "aa", "website_icon": "aa", "website_category": "Female" }, {"id": 1671308037, "rss_link": "bb", "website_name": "bb", "website_icon": "bb", "website_category": "Male" }, {"id": 1671308046, "rss_link": "cc", "website_name": "cc", "website_icon": "cc", "website_category": "Male" } ]
الى
{"0": {"id": 1671308031, "rss_link": "aa", "website_name": "aa", "website_icon": "aa", "website_category": "Female" }, "2": {"id": 1671308046, "rss_link": "cc", "website_name": "cc", "website_icon": "cc", "website_category": "Male" } }
هل من حل لهذه المشكلة
التعليقات