Skip to content
Advertisement

json with no index after unset encode array in php

I hope anyone can help me. My JSON isn’t indexed (i.e. there isn’t any key above any element)

JavaScript

but after running unset() to remove an element with PHP the output JSON appears like this:

JavaScript

How you can see there is a key before the element of JSON. I know that this behavior is caused by unset (PHP json_encode as object after PHP array unset()).

There is a way to prevent this behavior?

Advertisement

Answer

I searched and tried anyway to implement the behaviour that i searched in my question but i didn’t find nothing. I supposed that, like you can see in this answer, unset function adds indices to the array because the JSON_encode not support arrays with hole. So, to solve my problem, i load the JSON file with a jQuery function, delete the elements with jQuery and i call a ajax function to delete the files linked at the address contained in the json file:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement