php - sort array by custom criteria
问题 I have an array of objects: object1-> name="Name1" key="key1" object2-> name="Name2" key="key2" object3-> name="Name3" key="key3" and an array of priority keys: $keys = ["key3", "key1"]; I need to sort the array of objects based on priority keys, so the result should be: object3: name="Name3" key="key3" object1-> name="Name1" key="key1" object2: name="Name2" key="key2" What is the best way to do it? 回答1: The idea is to add a priority as integer, and sort the array from the highest integer to