1

JSON object always changes its sort order after conversion from PHP arrays to JSON is there any solution ?

asked Oct 16, 2022 at 8:32

1 Answer 1

0

JS objects don't have meaning to key sort order. If you need to keep the order similar to your PHP array - you can create an array with the keys (array_keys function), convert it to JSON (this will keep the order because its an array and not an object) and pass it along with the object it self, and in your JS or wherever you are parsing the badly ordered object - just use the array as the order for the object (loop over it and access the object key by the current array element).

answered Oct 17, 2022 at 11:03

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.